Skip to content

Instantly share code, notes, and snippets.

@bonelifer bonelifer/mysql_backup.sh
Last active Sep 14, 2015

Embed
What would you like to do?
mysql weekly Backup Script
#!/bin/sh
now="$(date +'%d_%m_%Y_%H_%M_%S')"
filename="mysql-kodi_backup_$now".gz
backupfolder="/media/5a24e136-09b9-48e1-95db-b44d5db3e28a/Backup/mysql"
fullpathbackupfile="$backupfolder/$filename"
logfile="$backupfolder/"backup_log_"$(date +'%Y_%m')".txt
echo "mysqldump started at $(date +'%d-%m-%Y %H:%M:%S')" >> "$logfile"
mysqldump --user=xbmc --password=xbmc --default-character-set=utf8 --single-transaction --all-databases | gzip > "$fullpathbackupfile"
echo "mysqldump finished at $(date +'%d-%m-%Y %H:%M:%S')" >> "$logfile"
chown root "$fullpathbackupfile"
chown root "$logfile"
echo "file permission changed" >> "$logfile"
find "$backupfolder" -name db_backup_* -mtime +8 -exec rm {} \;
echo "old files deleted" >> "$logfile"
echo "operation finished at $(date +'%d-%m-%Y %H:%M:%S')" >> "$logfile"
echo "*****************" >> "$logfile"
exit 0
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.