Comrade:MxAsh/AdminNotes/backup

Revision as of 00:47, 26 December 2020 by MxAsh (talk | contribs) (Created page with "=== on the server === We have a crontab running every 6 hours that runs a database backup: <pre># crontab -l | grep db_backup 10 */6 * * * /root/db_backup.sh >/dev/null 2>&1</...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

on the server

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

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.

#!/opt/homebrew/bin/bash -x

backupdir='/Volumes/home/Misc_Backups/prolewiki'

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

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