Skip to content

Instantly share code, notes, and snippets.

@bonelifer
Last active September 14, 2015 13:48
Show Gist options
  • Save bonelifer/e477d82025514d9ba88f to your computer and use it in GitHub Desktop.
Save bonelifer/e477d82025514d9ba88f to your computer and use it in GitHub Desktop.
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