So far this is what I've been using, I've copied it more or less from a couple of google searches.
- Code: Select all
#!/bin/sh
# Set date
THEDATE=`date +%d%m%y%H%M`
# Site 1
THESITE1="websitename"
THEDB1="db_name"
THEDBUSER1="dbusername"
THEDBPW1="dbpassword"
mysqldump -u $THEDBUSER1 -p${THEDBPW1} $THEDB1 | gzip > /home/user/sitebackups/files/dbbackup_${THEDB1}_${THEDATE}.bak.gz
tar czf /home/user/sitebackups/files/sitebackup_${THESITE1}_${THEDATE}.tar -C /var/www/html/ $THESITE1/
gzip /home/user/sitebackups/files/sitebackup_${THESITE1}_${THEDATE}.tar
# Uncomment and adjust to remove backups > 5days old
# find /var/www/html/$THESITE1/backups/files/site* -mtime +5 -exec rm {} \;
# find /var/www/html/$THESITE1/backups/files/db* -mtime +5 -exec rm {} \;
For ease of storage/migrating I'm thinking the tar step should add the db dump to it, so then there's only one file for a complete backup/migrating.
Couple quick questions:
A: Should I halt the webserver while the mariadb dump is performed?
B: Can anyone suggest any improvements or confirm this is ok?
I intend to chron this job.