Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Daily rotation not working #43

Open
GnaXi opened this issue Aug 10, 2020 · 5 comments
Open

Daily rotation not working #43

GnaXi opened this issue Aug 10, 2020 · 5 comments

Comments

@GnaXi
Copy link

GnaXi commented Aug 10, 2020

Hi,

I've set the "CONFIG_rotation_daily" to "1", but backups older than 24 hours are not being deleted.
I installed this on a server with very little space left, so when this feature wasn't working, the hard drive was full within 3 days.

@BigAndini
Copy link
Contributor

Can you please give some more information? For me it's working. So it's the backups of the last 3 days, not the last 3 backups. When I do some backups from today it can happen that the system keeps more than 3 backups.

Interesting information would be an ls -l from the folder of the database in the daily directory to check the timestamps.

Within the script it's a simple find /path/to/daily/db/backups -mtime +1 -type f -exec rm {} \;. So no special magic here.

@GnaXi
Copy link
Author

GnaXi commented Aug 11, 2020

-r-------- 1 root root 2146709504 Aug 10 01:03 daily_otrs_2020-08-10_01h00m_Monday.sql.gz
-r-------- 1 root root 19329774030 Aug 11 02:06 daily_otrs_2020-08-11_01h00m_Tuesday.sql.gz

Shouldn't the one from Monday have been deleted, when the Tuesday backup was created?

@BigAndini
Copy link
Contributor

So the rotation mechanism only deletes files when the mysqldump command beforehand was successful. Your dumps are quite different in size, maybe there was a failure in execution. I did a small test:

[10:54:48 andi@wave ~/delete-test]$ touch -t 202008090000 file3
[10:54:59 andi@wave ~/delete-test]$ touch -t 202008080000 file3
[10:55:02 andi@wave ~/delete-test]$ touch -t 202008090000 file3
[10:55:06 andi@wave ~/delete-test]$ touch -t 202008080000 file4
[10:55:08 andi@wave ~/delete-test]$ ls -ltr
total 0
-rw-rw-r-- 1 andi andi 0 Aug  8 00:00 file4
-rw-rw-r-- 1 andi andi 0 Aug  9 00:00 file3
-rw-rw-r-- 1 andi andi 0 Aug 10 00:00 file2
-rw-rw-r-- 1 andi andi 0 Aug 11 10:53 file1
[10:55:09 andi@wave ~/delete-test]$ find -mtime +1
./file4
./file3
[10:55:16 andi@wave ~/delete-test]$

In automysqldump the find command uses only -mtime without the -daystart parameter. So find should calculate 24h backwards. I don't know when exactly your command was executed, but it looks like it should have deleted the first file due to it was last modified at 01:03 and the second one at 02:06. So the find command to clean it up is executed after the mysqldump.

I did it in one of my setups: worked pretty fine.

@GnaXi
Copy link
Author

GnaXi commented Aug 20, 2020

You were absolutely right. It ran out of space before it was able to finish!
I'm playing around with a smaller database backup now, to make sure that it doesn't run out of space before it gets to finish the backup.
However, it still seems to be saving 3 days worth of daily backups:
-r-------- 1 root root 214230953 Aug 18 01:01 daily_otrs_2020-08-18_01h00m_Tuesday.sql.gz
-r-------- 1 root root 215314989 Aug 19 01:01 daily_otrs_2020-08-19_01h00m_Wednesday.sql.gz
-r-------- 1 root root 214583477 Aug 20 01:01 daily_otrs_2020-08-20_01h00m_Thursday.sql.gz

I can confirm that it is actually deleting backups older than these, as I've had it running for about a week now.

@ahindrichs
Copy link
Contributor

ahindrichs commented Sep 23, 2021

We have the same behaviour, with the setting "CONFIG_rotation_daily=1", which keeps three backup files.
Due to the size of the backup, we only want to save the last backup.

A solution can be to change mtime to mmin, like:

before:

find "${CONFIG_backup_dir}/${subfolder}${subsubfolder}" -mtime +"${rotation}" -type f -exec echo "dry-running: rm" {} \;
else
find "${CONFIG_backup_dir}/${subfolder}${subsubfolder}" -mtime +"${rotation}" -type f -exec rm {} \;

to:

find "${CONFIG_backup_dir}/${subfolder}${subsubfolder}" -mmin +"$((60*24*$rotation-60))" -type f -exec echo "dry-running: rm" {} \;
else
find "${CONFIG_backup_dir}/${subfolder}${subsubfolder}" -mmin +"$((60*24*$rotation-60))" -type f -exec rm {} \;

The behaviour should be compatible as far as it goes. If you want, I could create a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants