Database Backup
#!/bin/sh |
2 | now="$(date +'%d_%m_%Y_%H_%M_%S')" |
3 | filename="db_backup_$now".gz |
4 | backupfolder="/var/www/vhosts/example.com/httpdocs/backups" |
5 | fullpathbackupfile="$backupfolder/$filename" |
6 | logfile="$backupfolder/"backup_log_"$(date +'%Y_%m')".txt |
7 | echo "mysqldump started at $(date +'%d-%m-%Y %H:%M:%S')" >> "$logfile" |
8 | mysqldump --user=mydbuser--password=mypass --default-character-set=utf8 mydatabase | gzip > "$fullpathbackupfile" |
9 | echo "mysqldump finished at $(date +'%d-%m-%Y %H:%M:%S')" >> "$logfile" |
10 | chown myuser "$fullpathbackupfile" |
11 | chown myuser "$logfile" |
12 | echo "file permission changed" >> "$logfile" |
13 | find "$backupfolder" -name db_backup_* -mtime +8 -exec rm {} ; |
14 | echo "old files deleted" >> "$logfile" |
15 | echo "operation finished at $(date +'%d-%m-%Y %H:%M:%S')" >> "$logfile" |
16 | echo "*****************" >> "$logfile" |
17 | exit 0 |
0 Comments
Post a Comment