Answer the question
In order to leave comments, you need to log in
Can you help to correct the backup script to the desired condition?
All health!
I found a script for MYSQL database backup on the Internet , with the permission of the author, I post the code here:
#!/bin/bash
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
destination="/backup/mysql"
userDB="backup"
passwordDB="backup"
fdate=`date +%Y-%m-%d`
find $destination -type d \( -name "*-1[^5]" -o -name "*-[023]?" \) -ctime +30 -exec rm -R {} \; 2>&1
find $destination -type d -name "*-*" -ctime +180 -exec rm -R {} \; 2>&1
mkdir $destination/$fdate 2>&1
for dbname in `echo show databases | mysql -u$userDB -p$passwordDB | grep -v Database`; do
case $dbname in
information_schema)
continue ;;
mysql)
continue ;;
performance_schema)
continue ;;
test)
continue ;;
*) mysqldump --databases --skip-comments -u$userDB -p$passwordDB $dbname | gzip > $destination/$fdate/$dbname.sql.gz ;;
esac
done;
Здравствуйте.
Эти строки отвечают за удаление старых версий
find $destination -type d \( -name "*-1[^5]" -o -name "*-[023]?" \) -ctime +30 -exec rm -R {} \; 2>&1
find $destination -type d -name "*-*" -ctime +180 -exec rm -R {} \; 2>&1
Если Вам нужно хранить 5 копий, то замените 30 на 5. Будут оставаться только копии за 15 число, как архивные. Чтобы и их удалять, замените во второй строчке 180 на 30 или 60.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question