Drush Archives

Uit De Vliegende Brigade
Versie door Jeroen Strompf (overleg | bijdragen) op 14 feb 2016 om 00:13
(wijz) ← Oudere versie | Huidige versie (wijz) | Nieuwere versie → (wijz)
Naar navigatie springen Naar zoeken springen
  • Archiefbestand aanmaken: drush ard of drush ard --destination=~/in1/site-backup.tar
  • Archiefbestand deployen: Zie hieronder, want complexer.

drush ard

drush archive-dump of drush ard creëert een archief-bestand, inclusief bestanden en database. Deze archiefbestanden zijn beduidend kleiner dan wanneer ik zelf met bv. tar aan de slag ga. Drush ard genereert trouwens tar.gz-bestanden.

Simpel voorbeeld

Dit is doorgaans precies wat ik nodig heb:

drush ard

In dit geval wordt de backup geplaatst in de drush archive folder. De output van drush ard vermeld trouwens locatie + naam, dus geen zweet.

Met pad+bestandsnaam

drush ard --destination=/var/www/site/backups/example.tar

Alleen een bestandsnaam opgeven werkt trouwens niet:

drush ard examplesite-drush-archief
Archive saved to /home/hiero/drush-backups/archive-dump/20151020145004/none.20151020_145004.tar.gz

drush help ard

Backup your code, files, and database into a single file.

Examples:
 drush archive-dump                        Write an archive containing 3 sites in it.                                                         
 default,example.com,foo.com
 drush archive-dump @sites                 Save archive containing all sites in a multi-site.                                                 
 drush archive-dump default                Save archive to custom location.                                                                   
 --destination=/backups/mysite.tar                                                                                                            
 drush archive-dump                        Omits any .git directories found in the tree as well as sites/default/files.                       
 --tar-options="--exclude=.git                                                                                                                
 --exclude=sites/default/files"                                                                                                               
 drush archive-dump                        Placeholder %files is replaced with the real path for the current site, and that path is excluded. 
 --tar-options="--exclude=%files"

Arguments:
 sites                                     Optional. Site specifications, delimited by commas. Typically, list subdirectory name(s) under /sites.

Options:
 --description                             Describe the archive contents.                                                                            
 --destination                             The full path and filename in which the archive should be stored. 
                                           If omitted, it will be saved to the drush-backups directory and a filename will be generated.
 --generator                               The generator name to store in the MANIFEST file. The default is "Drush archive-dump".
 --generatorversion                        The generator version number to store in the MANIFEST file. The default is 6.2.0.
 --no-core                                 Exclude Drupal core, so the backup only contains the site specific stuff.
 --overwrite                               Do not fail if the destination file exists; overwrite it instead.
 --pipe                                    Only print the destination of the archive. Useful for scripts that don't pass --destination.
 --preserve-symlinks                       Preserve symbolic links.
 --tags                                    Add tags to the archive manifest. Delimit multiple by commas.
 --tar-options                             Options passed thru to the tar command.

Aliases: ard, archive-backup, arb

drush arr

Met drush archive-restore of drush arr zet je een archiefbestand terug. Dat is me nog nooit fatsoenlijk gelukt. Deze stap sla ik in de praktijk over, en doe het uitpakken en terugzetten handmatig.

Syntaxis:

drush arr [--destination] [--db-prefix] [--db-url] [--db-su] [-db-su-pw] [--overwrite] <bestandsnaam> <site-naam>

In sommige gevallen zul je drush uli nodig hebben om het beheer-wachtwoord te resetten.

Update Drush!

Ik heb sterk de indruk dat het een hoop ellende kan schelen als je eerst Drush update naar de nieuwste versie.

Voorbeeld --db-url

drush arr ./example.tar.gz --db-url=mysql://root:pass@127.0.0.1/dbname

Voorbeeld --destination

drush arr ./example.tar.gz --destination=/var/www/example.com/docroot

Let op het =-teken. Verder moet dit een lege map zijn.

Compleet voorbeeld

Handig om bv. een testsite snel te resetten

  • Verwijder de database en maak deze opnieuw aan (waarschijnlijk kan deze stap overgeslagen worden)
  • Verwijder alle bestanden (bv. met rm -rf * vanaf de juiste locatie)
  • Installeer het archief, bv. met zoiets als drush arr ./example.tar.gz --db-url=mysql://root:pass@127.0.0.1/dbname --destination=/var/www/example.com/docroot --overwrite. settings.php wordt automatisch bijgewerkt door Drush
  • Rechten bijwerken. Aangezien dit een ontwikkelomgeving betreft: chmod -R o+rwx .
  • Root-wachtwoord wijzigen: drush upwd --password="Wachtwoord" admin
  • $base_url aanpassen in settings.php

Denk ook aan...

  • Bestandspermissies
  • CleanURLs/Apache-configuratie/.htaccess
  • Base-path in settings.php

drush help arr

Expand a site archive into a Drupal web site.

Examples:
 drush archive-restore ./example.tar.gz    Restore the files and databases for all sites in the archive.                   
 drush archive-restore ./example.tar.gz    Restore the files and database for example.com site.                            
 example.com                                                                                                               
 drush archive-restore ./example.tar.gz    Restore archive to a custom location.                                           
 --destination=/var/www/example.com/docro                                                                                  
 ot                                                                                                                        
 drush archive-restore ./example.tar.gz    Restore archive to a new database (and customize settings.php to point there.). 
 --db-url=mysql://root:pass@127.0.0.1/dbn                                                                                  
 ame

Arguments:
 file                                      The site archive file that should be expanded.                                
 site name                                 Optional. Which site within the archive you want to restore. Defaults to all.

Options:
 --db-prefix                               An optional table prefix to use during restore.                                                                               
 --db-su                                   Account to use when creating the new database. Optional.                                                                      
 --db-su-pw                                Password for the "db-su" account. Optional.                                                                                   
 --db-url=<mysql://root:pass@host/db>      A Drupal 6 style database URL indicating the target for database restore. If not provided, the archived settings.php is used. 
 --destination                             Specify where the Drupal site should be expanded, including the docroot. Defaults to the current working directory.           
 --overwrite                               Allow drush to overwrite any files in the destination.

Aliases: arr

Zelf archief uitpakken & terugzetten

Zoals hierboven al beschreven: Ik geloof dat ik nog nooit met succes een Drush-archiefbestand aan de praat heb gekregen op de manier waarop het bedoeld is. Wat wel werkt:

tar -xzf <archiefbestand>.tar.gz

Nu heb je (naast het archiefbestand):

  • Map <hosting-account>
  • MANIFEST.ini - Negeren
  • <hosting-acount>.sql

Lees de database in:

mysql <databasenaam> < <hosting-account>.sql

Verplaats de uitgepakte bestanden naar de juiste locatie. Da's nog best lastig, als je de .dot-bestanden wilt behouden. Een oplossing die hier werkte: De doelmap verwijderen, en kopiëren + aanmaken van de doelmap als volgt doen:

cp -r bronmap ~/public/doelmap

Daarna werkte het in één keer: Ik hoefde geen bestandskenmerken aan te passen.

Casus okt. 2015: Site klonen naar locale kopie

Archiveren

drush arr --destination=~/in1/examplearchief

en vanaf m'n laptop:

scp mijnserver:in1/examplearchief /var/www/in

Database doellocatie

Database + gebruiker aanmaken op doellocatie:

create database examplecom;
grant all on examplecom.* to 'examplecom'@'localhost' identified by 'W@chtwoord';

Archief toepassen

Navigeer naar de juiste plek:

cd /var/www/in

Eerste poging - Dit geeft een foutmelding, omdat de doelmap niet de actieve map kan zijn:

drush arr examplearchief

Tweede poging:

drush arr examplearchief --destination=/var/www/example

Dit gaat ok, behalve dat er een tussenmap public is aangemaakt, en dat er geen bestand settings.php is.

Derde poging:

drush arr examplearchief --destination=/var/www/example --db-url=mysql://gebruiker:wachtwoord@localhost/databasenaam

Dit gaat goed. Er wordt nu ook geen tussemap public aangemaakt.

Zie ook

Bronnen