Difference between revisions of "Server backup and restore"

From MetaWiki
Jump to: navigation, search
m (Remote backup)
(addition of special backup)
 
Line 14: Line 14:
 
The backup is initiated by a cron job specified in /etc/crontab. At 2:06 it calls <code>daily_bak_entry.sh</code>. The entry script only calls <code>daily_bak_master.sh</code> and forwards the output (stdout and stderr) into a temporary file which is afterwards moved to <code>/var/log/backups/</code>  so it is possible to determine what when wrong if somethings goes wrong.  
 
The backup is initiated by a cron job specified in /etc/crontab. At 2:06 it calls <code>daily_bak_entry.sh</code>. The entry script only calls <code>daily_bak_master.sh</code> and forwards the output (stdout and stderr) into a temporary file which is afterwards moved to <code>/var/log/backups/</code>  so it is possible to determine what when wrong if somethings goes wrong.  
  
The master script removed the outdated backups as outlined above and then calls the other backup scripts
+
The master script removes the outdated backups as outlined above and then calls the other backup scripts
 
* daily_bak_mysql.sh
 
* daily_bak_mysql.sh
 
* daily_bak_settings.sh
 
* daily_bak_settings.sh
 
* daily_bak_svn.sh
 
* daily_bak_svn.sh
 
* daily_bak_wiki_media.sh
 
* daily_bak_wiki_media.sh
 +
* daily_bak_special.sh
  
After the backups are done, the resulting files from the mysql, settings and svn (not wiki though) backups are copied to <code>/mnt/dump/var/backups/WEEKLY</code> or <code>/mnt/dump/var/backups/MONTHLY</code> if it is the first day of the week (Monday) or of the month respectively.  
+
After the backups are done, the resulting files from the mysql, settings and svn (not wiki and special though) backups are copied to <code>/mnt/dump/var/backups/WEEKLY</code> or <code>/mnt/dump/var/backups/MONTHLY</code> if it is the first day of the week (Monday) or of the month respectively.  
  
 
== MySQL backup ==
 
== MySQL backup ==
Line 70: Line 71:
 
It is possible to specify wikis which should not be backed up like this. This could be useful for wikis that have their own backup strategy, like practical plans. In order to have a wiki be ignored, add the path to the variable '''WIKIEXCLUDELIST''' at the beginning of the script (space separated). Any wikis below this path will be ignored, even if they are within subdirectories:
 
It is possible to specify wikis which should not be backed up like this. This could be useful for wikis that have their own backup strategy, like practical plans. In order to have a wiki be ignored, add the path to the variable '''WIKIEXCLUDELIST''' at the beginning of the script (space separated). Any wikis below this path will be ignored, even if they are within subdirectories:
 
  WIKIEXCLUDELIST="v-practicalplants v-mfn/w/extensions2/WYSIWYG v-mfn/sammlung/extensions2.BACKUP"
 
  WIKIEXCLUDELIST="v-practicalplants v-mfn/w/extensions2/WYSIWYG v-mfn/sammlung/extensions2.BACKUP"
 +
 +
== Special backup ==
 +
The daily backup of special tasks is performed by the script
 +
/etc/backupscripts/daily_bak_special.sh
 +
 +
It contains the backup of the directory <code>/var/www/v-practicalplants</code>. This directory is deliberately not covered by the script <code>daily_bak_wiki_media.sh</code>.
 +
 +
Another archive is created for <code>/var/www</code> which contains all the files and directories except the various <code>cache/</code> and <code>media/</code> directories and <code>v-practicalplants</code>. Unlike the wikisettings backup above, this one contains also files from non-wiki folders and customized wiki files, (e.g. extensions2/).
 +
 +
The resulting files is stored in <code><back_up_dir>/DAILY/special</code>.
 +
 +
Both backups are not part of the daily/weekly/monthly replication, due to their size. However the most recent backup is coped into <code><back_up_dir>/DAILY/special/old</code> before the next backup is started, so that one valid backup remains, in case the backup process fails.
 +
  
 
== Remote backup ==
 
== Remote backup ==

Latest revision as of 16:24, 14 October 2015

Contents

[edit] Strategies

Wikis: Both the media folders and mysql databases need regular backup and validation of restore. We can run a backup to a separate disk, which is mounted at /mnt/dump and mapped; with /var/backups mapped to /mnt/dump/var/backups. Thus writing a backup to /var/backups will end up on this disk.

Backup scripts are currently stored at: /etc/backupscripts/

We want a combination of rsync for heavily used resources (especially the media folders or wikis, and other media storage) and versioned, 7-zipped backup (to protect against user-error as well as hardware failure). The versioning schema is planned to be 7 daily versions (cyclically overwritten), 5 weekly ones (cyclically overwritten), 12 monthly ones (cyclically overwritten), yearly ones (not overwritten). That is after the first year, one has 7 + 5 + 12 + years = 24 + yearly copies.

Versioned backup should be /etc and /home weekly, and /var (without backup, mysql db and media folders) daily.

[edit] Initiating the backup

The backup is initiated by a cron job specified in /etc/crontab. At 2:06 it calls daily_bak_entry.sh. The entry script only calls daily_bak_master.sh and forwards the output (stdout and stderr) into a temporary file which is afterwards moved to /var/log/backups/ so it is possible to determine what when wrong if somethings goes wrong.

The master script removes the outdated backups as outlined above and then calls the other backup scripts

  • daily_bak_mysql.sh
  • daily_bak_settings.sh
  • daily_bak_svn.sh
  • daily_bak_wiki_media.sh
  • daily_bak_special.sh

After the backups are done, the resulting files from the mysql, settings and svn (not wiki and special though) backups are copied to /mnt/dump/var/backups/WEEKLY or /mnt/dump/var/backups/MONTHLY if it is the first day of the week (Monday) or of the month respectively.

[edit] MySQL backup

The daily backup of all of mysql databases is performed by the script

/etc/backupscripts/daily_bak_mysql.sh

The backup files are located in

/mnt/dump/var/backups/DAILY/mysql/

and is named as:

YY-MM-DD_DBNAME.sql.7z

By default it exports all the databases within mysql. In the script there is a variable DBSKIP that contains names of databases to skip, for example:

DBSKIP="information_schema|wmf_commons|wmf_dewiki"

[edit] SVN backup

The daily backup of svn repository is performed by the script

/etc/backupscripts/daily_bak_svn.sh

The backup files are located in

/mnt/dump/var/backups/DAILY/mysql/

and is named as:

YY-MM-DD_var_lib_svn.tar.7z

It backups everything within /var/lib/svn/.


[edit] Settings backup

The daily backup of various settings is performed by the script

/etc/backupscripts/daily_bak_settings.sh

The backup files are located in

/mnt/dump/var/backups/DAILY/settings/

and is named as:

YY-MM-DD_etc.tar.7z

It backups everything within /etc/ and /var/spool/cron/crontabs/.


[edit] MediaWiki media folder and settings backup

The daily backup of media wikis is performed by the script

/etc/backupscripts/daily_bak_wiki_media.sh

It searches for all the files called LocalSettings.php within /var/www and all its subdirectories, regardless of the depth. For each directory in which a LocalSettings.php it backups all the LocalSetting* files one tar and it synchronizes the media directory.

The media directories are synchronized using rsyncto the corresponding subdir in
/mnt/dump/var/backups/DAILY/wikis/

The backup of all the LocalSetting* files as well as all the *.php files within /var/www (without subdirectories)

and stored in
/mnt/dump/var/backups/DAILY/wikis/
in a file called
wikisettingsYY-MM-DD.tar.7z

It is possible to specify wikis which should not be backed up like this. This could be useful for wikis that have their own backup strategy, like practical plans. In order to have a wiki be ignored, add the path to the variable WIKIEXCLUDELIST at the beginning of the script (space separated). Any wikis below this path will be ignored, even if they are within subdirectories:

WIKIEXCLUDELIST="v-practicalplants v-mfn/w/extensions2/WYSIWYG v-mfn/sammlung/extensions2.BACKUP"

[edit] Special backup

The daily backup of special tasks is performed by the script

/etc/backupscripts/daily_bak_special.sh

It contains the backup of the directory /var/www/v-practicalplants. This directory is deliberately not covered by the script daily_bak_wiki_media.sh.

Another archive is created for /var/www which contains all the files and directories except the various cache/ and media/ directories and v-practicalplants. Unlike the wikisettings backup above, this one contains also files from non-wiki folders and customized wiki files, (e.g. extensions2/).

The resulting files is stored in <back_up_dir>/DAILY/special.

Both backups are not part of the daily/weekly/monthly replication, due to their size. However the most recent backup is coped into <back_up_dir>/DAILY/special/old before the next backup is started, so that one valid backup remains, in case the backup process fails.


[edit] Remote backup

Since internal backup has beeen running satisfactorily for the past 2 years (to date November 2014), external backups are no longer required. The script can be removed from crontab. The "backup" section in /etc/crontab should look like this:

### backups:
6 6 * * * root /etc/backupscripts/daily_bak_entry.sh

The file /etc/backupscripts/remote_bak_manol.sh can be removed.

See also: Testing /etc/crontab

[edit] Filling disk with null

cd /mnt/dump/; sudo dd if=/dev/zero bs=2048 of=/mnt/dump/file1

Reason: if backup shall be compressed, this will drastically increase compressibility. Danger: watch this with df -h, else it will fill each mount completely, potentially crashing the server.

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox