Difference between revisions of "Server backup and restore"
(updated documentation to reflect current backup strategy) |
(corrected DBSKIP value for mysql script) |
||
Line 32: | Line 32: | ||
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: | 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| | + | DBSKIP="information_schema|wmf_commons|wmf_dewiki" |
== SVN backup == | == SVN backup == |
Revision as of 09:41, 28 July 2014
Contents
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.
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 removed 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
After the backups are done, the resulting files from the mysql, settings and svn (not wiki 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.
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"
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/
.
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/
.
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.
rsync
to 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)
/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"
Remote backup
The daily remote backup of these dirs:
/mnt/dump/var/backups/wikis/ /mnt/dump/var/backups/mysql/
is performed by the script
/var/backupscripts/remote_bak_manol.sh
It is executed as cron job at 03:33 every night and make rsync of specified dirs to remote server
k2n.bikam.com
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.