篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh db / file备份脚本相关的知识,希望对你有一定的参考价值。
#!/bin/bash
sitedir="/srv/www"
filedir="/root/file_backups/today"
logs="/root/file_backups/logs"
tbackups="/root/file_backups/today"
ybackups="/root/file_backups/yesterday"
curday=$(date +"%_d")
echo "`date`" > $logs/backups.log
rm $ybackups/* >> $logs/backups.log
mv $tbackups/* $ybackups/ >> $logs/backups.log
cd "$sitedir"
for i in */; do
tar -czf $tbackups/${i%%/}".tar.gz" ${i%%/}
echo -e "\r\nBackup of ${i%%/} successfull" >> $logs/backups.log
done
cd "$filedir"
for i in */; do
if [ $curday -eq 14 ]; then
scp ${i%%/}".tar.gz" u106143@u106143.your-backup.de:/file_backups/14th
elif [ $curday -eq 28 ]; then
scp ${i%%/}".tar.gz" u106143@u106143.your-backup.de:/file_backups/28th
fi
done
exit 0
#!/bin/bash
logs="/root/db_backups/logs"
bdir="/root/db_backups/today"
mysql_user="backup"
mysql_password="webiumbackup"
mysql=/usr/bin/mysql
mysqldump=/usr/bin/mysqldump
tbackups="/root/db_backups/today"
ybackups="/root/db_backups/yesterday"
curday=$(date +"%_d")
echo "`date`" > $logs/backups.log
rm $ybackups/* >> $logs/backups.log
mv $tbackups/* $ybackups/ >> $logs/backups.log
databases=`$mysql --user=$mysql_user -p$mysql_password -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema)"`
for db in $databases; do
$mysqldump --force --opt --user=$mysql_user -p$mysql_password $db | gzip > "$tbackups/$db.gz"
echo -e "\r\nBackup of $db successfull" >> $logs/backups.log
done
cd $bdir
for i in */; do
if [ $curday -eq 7 ]; then
scp ${i%%/}".gz" u106143@u106143.your-backup.de:/db_backups/7th
elif [ $curday -eq 14 ]; then
scp ${i%%/}".gz" u106143@u106143.your-backup.de:/db_backups/14th
elif [ $curday -eq 21 ]; then
scp ${i%%/}".gz" u106143@u106143.your-backup.de:/db_backups/21th
elif [ $curday -eq 28 ]; then
scp ${i%%/}".gz" u106143@u106143.your-backup.de:/db_backups/28th
fi
done
exit 0