Difference between revisions of "Backup Website Data w/ MySQL"

From Michael's Information Zone
Jump to navigation Jump to search
(Created page with "<syntaxhighlight lang="BASH"> #!/bin/bash date=$(date +%Y-%m-%d) olddate=$(date --date="1 week ago" +%Y-%m-%d) mysqldump --all-databases -p<DBPassword> /root/dbbackup/database...")
 
 
Line 4: Line 4:
 
olddate=$(date --date="1 week ago" +%Y-%m-%d)
 
olddate=$(date --date="1 week ago" +%Y-%m-%d)
 
mysqldump --all-databases -p<DBPassword> /root/dbbackup/database_$date.sql
 
mysqldump --all-databases -p<DBPassword> /root/dbbackup/database_$date.sql
rm -f /dbbackup/database_$olddate.sql
+
rm -f /root/dbbackup/database_$olddate.sql
 
cp -r /root/webbackup /root/sitebackup/daily_$date
 
cp -r /root/webbackup /root/sitebackup/daily_$date
 
rsync -av --delete /var/www /root/webbackup/
 
rsync -av --delete /var/www /root/webbackup/

Latest revision as of 15:05, 17 May 2016

#!/bin/bash
date=$(date +%Y-%m-%d)
olddate=$(date --date="1 week ago" +%Y-%m-%d)
mysqldump --all-databases -p<DBPassword> /root/dbbackup/database_$date.sql
rm -f /root/dbbackup/database_$olddate.sql
cp -r /root/webbackup /root/sitebackup/daily_$date
rsync -av --delete /var/www /root/webbackup/
rm -f /root/sitebackup/daily_%olddate

####The following is for managing disk space, will be visited later.
#df -lh /dev/sda2 --output=ipcent > /tmp/percent
#grep '^ ' /tmp/percent > /tmp/percent1
#rm /tmp/percent
#disk=$(sed 's/^\ \ \ //' /tmp/percent1)
#diskused=$(sed 's/%//' < $disk)
#unset disk
#if ( $diskused <= 10 ); then
#rm /root/old/*