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

Comrade:MxAsh/AdminNotes/backup: Difference between revisions

More languages
mNo edit summary
m (updated script)
Line 25: Line 25:
#!/opt/homebrew/bin/bash -x
#!/opt/homebrew/bin/bash -x


backupdir='/Volumes/home/Misc_Backups/prolewiki' # change to your local backup directory
backupdir='/Volumes/home/Misc_Backups/prolewiki'


if [[ ! -d ${backupdir} ]]; then
if [[ ! -d ${backupdir} ]]; then
   echo "Cannot access backup directory \`${backupdir}\`, is nas2 mounted?" 1>&2
   echo "Cannot access backup directory \`${backupdir}\`, exiting" 1>&2
   exit 2
   exit 2
fi
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:/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</pre>
time rsync -ave 'ssh -p 22022' --delete root@www.prolewiki.org:/root/databases/ ${backupdir}/database/ 2>&1 | tee ${backupdir}/databases_rsync.log</pre>

Revision as of 00:59, 26 December 2020

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.

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

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

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