Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Comrade:MxAsh/AdminNotes/backup

More languages

on the server[edit | edit source]

We have a crontab running every 6 hours that runs a database backup:

# crontab -l | grep db_backup
10 */6 * * * /root/db_backup.sh >/dev/null 2>&1
$ cat /root/db_backup.sh
#!/usr/bin/bash -x

backupdir='/root/databases'
datestamp="$(date +%Hh%d-%m-%Y)"

if [[ ${EUID} -ne 0 ]]; then
  echo "This program expects to be run as root." 1>&2
  exit 127
fi

mysqldump --add-drop-database --log-error=${backupdir}/pw-server_all_${datestamp}.sql.log --verbose --result-file=${backupdir}/pw-server_all_${datestamp}.sql --all-databases
find ${backupdir} -mtime +1 -print -delete 2>&1 | tee ${backupdir}/pw-server_all_${datestamp}.cleanup.log

local backup script[edit | edit source]

TODO

  • some kind of archival and/or versioning of the webroot? (right now I get it from the backup host filesystem)

If you run this yourself you'll need to change the "shebang" line referencing bash, and the backupdir.

$ cat bin/wikibackup_pull.sh
#!/opt/homebrew/bin/bash -x

backupdir='/Volumes/home/Misc_Backups/prolewiki'
datestamp="$(date +%Hh%d-%m-%Y)"

if [[ ! -d ${backupdir} ]]; then
  echo "Cannot access backup directory \`${backupdir}\`, exiting" 1>&2
  exit 2
fi

mkdir -pv ${backupdir}/{database,public_html}/

time rsync -ave 'ssh -p 22022' --delete root@www.prolewiki.org:/home/prole/public_html/ ${backupdir}/public_html/ 2>&1 | tee ${backupdir}/public_html_rsync.log
time rsync -ave 'ssh -p 22022' --delete root@www.prolewiki.org:/root/databases/ ${backupdir}/database/ 2>&1 | tee ${backupdir}/databases_rsync.log

zip -Tr ${backupdir}/${datestamp}.zip ${backupdir}/database ${backupdir}/public_html