Server backup and restore

From MetaWiki
Jump to: navigation, search



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/backup/ and is also linked from /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.

Initiating the backup

The backup is initiated by a cron job specified in /etc/crontab. At 2:06 it calls The entry script only calls 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 first checks if the backup drive /mnt/backup is mounted. If it is not (this could be caused by a mounting issue with the NFS drive), it uses the secondary local hard drive mounted at /mnt/dump as alternative. The backups would in this case be saved at /mnt/dump/var/backups/.

Next, the main script removes the outdated backups as outlined above and then calls the task specific backup scripts


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

MySQL backup

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


The backup files are located in


and is named as:


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:


SVN backup

The daily backup of svn repository is performed by the script


The backup files are located in


and is named as:


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

Settings backup

The daily backup of various settings is performed by the script


The backup files are located in


and is named as:


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

MediaWiki media folder and settings backup

The daily backup of media wikis is performed by the script


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

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

and stored in
in a file called

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"

Special backup

The daily backup of special tasks is performed by the script


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

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.

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/

The file /etc/backupscripts/ can be removed.

See also: Testing /etc/crontab

Filling disk with null

cd /mnt/backup/; sudo dd if=/dev/zero bs=2048 of=/mnt/backup/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.

Backup Size

Based on the current data that is backed up (as of July 2016), the complete backup will take up around 320 GB.

243.9 GB DAILY (kept for 8 days)
 20.5 GB DAILY/mysql
  0.1 GB DAILY/settings
  3.8 GB DAILY/special
  0.5 GB DAILY/svn
219.0 GB DAILY/wikis

 13.2 GB WEEKLY (keep for 5 month)
 12.8 GB WEEKLY/mysql
  0.1 GB WEEKLY/settings
  0.3 GB WEEKLY/svn

 63.6 GB MONTHLY (kept for 24 month)
 61.6 GB MONTHLY/mysql 
  0.5 GB MONTHLY/settings
  1.5 GB MONTHLY/svn

320   GB Total
Personal tools