Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
BACKUP_BASE_DIR=/home/kyle/backups
BACKUP_FS_MANIFEST=/etc/backups/fs_manifest
BACKUP_DB_MANIFEST=/etc/backups/db_manifest
TODAY_DATE=$(date "+%Y%m%d")
TODAY_DIR=${BACKUP_BASE_DIR}/${TODAY_DATE}
logger() {
printf "[$(date)] ${1}\n" | sudo tee -a /var/log/backups.log
}
mkdir -p ${TODAY_DIR}
logger "Created ${TODAY_DIR}"
# database backups
for database in $(cat ${BACKUP_DB_MANIFEST})
do
if [ ! -d ${TODAY_DIR}/database ]; then
mkdir -p ${TODAY_DIR}/database
logger "Created ${TODAY_DIR}/database"
fi
DATE=$(date "+%Y%m%dT%H%M%Y")
DATABASE_OUT=${TODAY_DIR}/database/${database}_${DATE}.sql
logger "Dumping ${database} database to ${DATABASE_OUT}"
mysqldump -u root -p ${database} > ${DATABASE_OUT}
done
# filesystem
for fs_path in $(cat ${BACKUP_FS_MANIFEST})
do
logger "Backing up ${fs_path}"
rsync -rRat ${fs_path} ${TODAY_DIR}/filesystem/
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.