Tecnico:Backup strutture
The help pages are provided by Hipatia volunteers to help wiki contributors. |
Help index: Mediawiki — Server configuration — LaTeX — Streaming — Templates |
Search for help: |
Backup dei siti
In questa pagina vengono riassunti tutti i passi che ci sono da fare per backuppare i nostri siti, ossia: Drupal, Wiki, Gallery.
Prerequisiti:
- accesso ssh al server dove stanno i file
- buona banda :)
- sul server ci devono essere:
- tar
- gzip
- mysqldump
- date
- rsync
- nice
Una cosa intelligente da fare e' passare i comandi a nice, in modo che essi abbiano una priprita' bassa e non sovraccarichino il server prima di ogni comando dare <syntaxhighlight lang="bash" enclosure="div">nice -n 19</syntaxhighlight>
N.B: e' buona prassi che per ogni web application (mediawiki, drupal, gallery) sia disponibile sul server la stessa versione del software in uso, ancora in formato tar.gz . Infatti tutti i programmi che si basano su mysql per funzionare, richiedono che i backup siano ripristinati con la stessa versione di software su cui erano stati fatti.
Ad esempio, se noi usiamo Drupal 6.16 e ne facciamo un backup, la prima volta che vorremo ripristinare i file cosi backuppati, dovremo farlo utilizzando la stessa versione di drupal (nel nostro esempio la 6.16). Nel caso in cui a quel tempo avremo una versione piu' aggiornata, occorrera' comunque partire dalla 6.16 e avanziare di una versione per volta, in modo da non danneggiare i dati (es permessi, testi, immagini, utenti, password, ecc).
Se quindi nella directory in cui abbiamo drupal, teniamo anche una versione inutilizzata del suo codice (drupal-6.16.tar.gz) allora saremo in una botte di ferro :)
Drupal
Per quanto riguarda drupal e' necessario copiare:
- il codice di drupal, nella versione .tar.gz
- il database di drupal. Cio' e' molto comodo e facile grazie all'estensione "Backup and Migrate", che permette di fare il tutto direttamente da web.
- Nota: e' saggio tenersi anche una copia del codice del modulo Backup and Migrate.
- la directory che contiene i file di drupal, ossia le configurazioni, i file uploadati, ecc.
- Per backuppare la directory e' sufficiente fare:
- <syntaxhighlight lang="bash" enclose="div">tar -czf drupal-$(date '+%d%m%Y').tar.gz $DRUPAL_DIR</syntaxhighlight>
Ricordarsi di fare rsync dei dati in locale :)
Mediawiki
- Cosi come per drupal, copiare il tar.gz del codice
- Mettere il wiki in read-only mode. Per farlo e' sufficiente editare il file LocalSettings.php e aggiungere la riga:
- <syntaxhighlight lang="php" enclosure="div">$wgReadOnly = "We are upgrading MediaWiki, please be patient. This wiki will be back in a few hours.";</syntaxhighlight>
- Backuppare il database:
- <syntaxhighlight lang="bash" enclose="div">nice -n 19 /usr/bin/mysqldump -u $USER --password=$PASSWORD --default-character-set=latin1 $DATABASE -c | nice -n 19 /bin/gzip -9 > wiki_hipatia-sql-$(date '+%d%m%Y').sql.gz</syntaxhighlight>
NOTA IMPORTANTE!!!! Prima di tutto e' importantissimo assicurarsi che il character set del database sia corretto, altrimenti tutti i contenuti testuali verranno corrotti!
Per controllare il character set:
- leggere in LocalSettings.php
- loggarsi in mysql: <syntaxhighlight lang="bash">mysql -u root -p</syntaxhighlight>
- entrare nel db: <syntaxhighlight lang="mysql">use $DATABASE;</syntaxhighlight>
- dare il comando <syntaxhighlight lang="mysql">status;</syntaxhighlight>
- controllare la voce server character set.
Ovviamente $USER, $PASSWORD, $DATABASE, si trovano in LocalSettings.php
NOTA: l'utente $USER deve avere i privilegi LOCK TABLES e SELECT su $DATABASE, altrimenti il comando mysqldump restituira' un errore.
- Fatto questo si devono ancora backuppare tutti i file del wiki: <syntaxhighlight lang="bash" enclose="div">tar -czf $WIKI_DIR wiki_hipatia_dir-$(date '+%d%m%Y').tar.gz</syntaxhighlight>
- fare un backup XML dei contenuti del wiki: <syntaxhighlight lang="bash" enclose="div">php -d error_reporting=E_ERROR $WIKI_DIR/maintenance/dumpBackup.php --full | gzip > wiki_hipatia-xml-$(date '+%d%m%Y').xml.gz</syntaxhighlight>
NOTA: perche' cio' sia possibile occorre aggiungere le seguenti due righe in LocalSettings.php: <syntaxhighlight lang="php" enclose="div">$wgDBadminuser = "$USER"; $wgDBadminpassword = "$PASSWORD";</syntaxhighlight>
- rimettere il wiki in read/write mode, commentando la riga aggiunta al punto 2.
Ripristinare Mediawiki
Per ripristinare un backup occorre:
- Creare il database:
- <syntaxhighlight lang="bash" enclosure="div">mysql -u root -p</syntaxhighlight>
- <syntaxhighlight lang="mysql" enclosure="div">create database $DATABASE;</syntaxhighlight>
- Recuperare il db dal backup:
- <syntaxhighlight lang="bash" enclosure="div">gunzip wiki_hipatia-sql-$(`date +%d%m%Y).sql.gz</syntaxhighlight>
- <syntaxhighlight lang="bash" enclosure="div">mysql -u root -p $DATABASE < wiki_hipatia-sql-$(`date +%d%m%Y).sql</syntaxhighlight>
- Controllare che il database sia funzionante:
- <syntaxhighlight lang="bash" enclosure="div">mysql -u root -p $DATABASE</syntaxhighlight>
- <syntaxhighlight lang="mysql" enclosure="div">show tables;</syntaxhighlight>
dovrebbero esserci tutte le tabelle (circa 35).
- Creare un utente $USER in mysql: <syntaxhighlight lang="bash" enclosure="div">mysql -u root -p</syntaxhighlight> <syntaxhighlight lang="mysql" enclosure="div">create user '$USER'@'localhost' IDENTIFIED BY '$PASSWORD';</syntaxhighlight> NOTA: $USER, $DATABASE e $PASSWORD devono essere gli stessi del LocalSettings.php del backup!
- dare i priviegi a $USER su $DATABASE: <syntaxhighlight lang="mysql" enclosure="div">GRANT ALL ON $DATABASE.* TO '$USER'@'localhost' IDENTIFIED BY '$PASSWORD'; FLUSH PRIVILEGES;</syntaxhighlight>
Fatto questo bisogna ancora recuperare i file e le immagini del wiki backuppato: <syntaxhighlight lang="bash" enclosure="div">tar xvzf wiki_hipatia_dir-$(`date +%d%m%Y`).tar.gz</syntaxhighlight>
NOTA: potrebbe essere necessario eseguire $WIKI_DIR/maintenance/rebuildall.php in questo modo: <syntaxhighlight lang="bash" enclosure="div">php $WIKI_DIR/maintenance/rebuildall.php</syntaxhighlight>
Controllare che la posizione del wiki sia corretta in LocalSettings.php. Non resta ora che testare il wiki.
Gallery
- Backuppare il codice del gallery, in versione tar.gz
- copiare il codice in uso del gallery:
- <syntaxhighlight lang="bash" enclosure="div">tar -czf $GALLERY_DIR gallery_dir-$(date '+%d%m%Y').tar.gz</syntaxhighlight>
- copiare gli album fotografici:
- <syntaxhighlight lang="bash" enclosure="div">tar -czf $GALLERY_DIR gallery_dir-$(date '+%d%m%Y').tar.gz
tar -czf $ALBUMS_DIR gallery_albums-$(date '+%d%m%Y').tar.gz</syntaxhighlight>
- backuppare il db del gallery (contiene tutte le descrizioni delle foto, gli utenti, i tag, ecc.)
- <syntaxhighlight lang="bash" enclosure="div">mysqldump -u $USER --password=$PASSWORD --default-character-set=latin1 $DATABASE -c | gzip -9 > gallery-sql-$(date '+%d%m%Y').sql.gz</syntaxhighlight>
- dove $USER $PASSWORD e $DATABASE sono reperibili in config.php