I use my Mint (20.2 Cinnamon) computer to work on local websites, and have an Apache webserver with PHP and MySQL running. I need to backup local databases and have come up with the following script in /etc/anacrontab file:
Code: Select all
1 15 purgetmp find /var/www/mysql_backup -type f -mtime +7 -delete > /dev/null
1 15 mysql_backup mkdir -p /var/www/mysql_backup ; mysqldump -u root -psesame --all-databases | /bin/gzip -9 > /var/www/mysql_backup/`date '+%F'`.databases.sql.gz ; rm -f /var/www/mysql_backup/`date '+%F' --date '1 week ago'`.databases.sql.gz
1) the first line seems to me redundant with the second, as it seems to me that both delete the backups older than 7 days (?)
2) if the computer is turned off for several days, the older backups get deleted when they are more than 7 days old. Therefore, if the computer is off for more than 7 days, all backups get deleted and only one is kept after running the script.
I would prefer to always keep the last 7 backups, regardless of their age
Could one of you knowledgeable people give me indications on how to achieve my goal? Thank you very much