Cron Rsnapshot – Fixing Backup Schedule Issues

cronrsnapshot

I'm setting up backups with rsnapshot. It is now running by cron, but not when/in the interval I intended it to.

Below is the schedule. It's this way to minimize overlapping backups. This should generate 8 backups every half hour, then 8 backups every hour, then 18 backups every two hour, and so on.

Hour         0     1     2     3     4     5     6     7     8     9     10     11
-------------|-------------------------------------------------------------------
half-hourly  |  x     x     x     x
hourly       |     x           x           x           x           x           x
two-hourly   |           x           x           x           x           x           x... (24)
daily        |(7)
weekly       |(4)

Extraction from /etc/rsnapshot

interval        halfhourly      4
interval        hourly  6
interval        twohourly       24
interval        daily   7
interval        weekly  4

This is the result, running from monday 00:00 to 14:00.

root@hemulen:~# ls -lat /var/backups/snapshots/
total 48
drwxr-xr-x 12 root root 4096 Sep 20 13:32 .
drwxr-xr-x  4 root root 4096 Sep 20 13:32 halfhourly.0
drwxr-xr-x  4 root root 4096 Sep 20 12:32 halfhourly.1
drwxr-xr-x  4 root root 4096 Sep 20 11:32 halfhourly.2
drwxr-xr-x  4 root root 4096 Sep 20 10:32 halfhourly.3
drwxr-xr-x  4 root root 4096 Sep 20 09:33 hourly.0
drwxr-xr-x  4 root root 4096 Sep 20 07:32 hourly.1
drwxr-xr-x  4 root root 4096 Sep 20 05:32 hourly.2
drwxr-xr-x  4 root root 4096 Sep 20 03:32 hourly.3
drwxr-xr-x  3 root root 4096 Sep 20 02:38 ..
drwxr-xr-x  4 root root 4096 Sep 20 02:33 hourly.4
drwxr-xr-x  4 root root 4096 Sep 20 01:32 hourly.5

This is the crontab.

30 * * * * /usr/bin/rsnapshot halfhourly >> /var/log/rsnapshot.run.log 2>&1
0 1,3,5,7,9,11,13,15,17,19,21,23 * * * /usr/bin/rsnapshot hourly >> /var/log/rsnapshot.run.log 2>&1
0 */2 * * * /usr/bin/rsnapshot two-hourly >> /var/log/rsnapshot.run.log 2>&1
0 3 * * * /usr/bin/rsnapshot daily >> /var/log/rsnapshot.run.log 2>&1
0 6 * * MON /usr/bin/rsnapshot weekly >> /var/log/rsnapshot.run.log 2>&1

What am I doing wrong, what am I missing here?


I changed it, and it has now been running for a week. I lowered two-hourly to store 12 backups.

drwxr-xr-x  5 root   root   4096 Sep 27 09:33 halfhourly.0
drwxr-xr-x  5 root   root   4096 Sep 27 09:03 halfhourly.1
drwxr-xr-x  5 root   root   4096 Sep 27 08:33 halfhourly.2
drwxr-xr-x  5 root   root   4096 Sep 27 08:04 halfhourly.3
drwxr-xr-x  5 root   root   4096 Sep 27 07:33 hourly.0
drwxr-xr-x  5 root   root   4096 Sep 27 06:33 hourly.1
drwxr-xr-x  5 root   root   4096 Sep 27 05:33 hourly.2
drwxr-xr-x  5 root   root   4096 Sep 27 04:33 hourly.3
drwxr-xr-x  5 root   root   4096 Sep 27 02:33 hourly.4
drwxr-xr-x  5 root   root   4096 Sep 27 01:33 hourly.5
drwxr-xr-x  5 root   root   4096 Sep 27 00:33 twohourly.0
drwxr-xr-x  5 root   root   4096 Sep 26 22:33 twohourly.1
drwxr-xr-x  5 root   root   4096 Sep 26 21:33 twohourly.2
drwxr-xr-x  5 root   root   4096 Sep 26 19:33 twohourly.3
drwxr-xr-x  5 root   root   4096 Sep 26 17:33 twohourly.4
drwxr-xr-x  5 root   root   4096 Sep 26 15:33 twohourly.5
drwxr-xr-x  5 root   root   4096 Sep 26 13:33 twohourly.6
drwxr-xr-x  5 root   root   4096 Sep 26 11:33 twohourly.7
drwxr-xr-x  5 root   root   4096 Sep 26 09:33 twohourly.8
drwxr-xr-x  5 root   root   4096 Sep 26 07:33 twohourly.9
drwxr-xr-x  5 root   root   4096 Sep 26 05:34 twohourly.10
drwxr-xr-x  5 root   root   4096 Sep 26 02:33 twohourly.11
drwxr-xr-x  5 root   root   4096 Sep 25 21:33 daily.0
drwxr-xr-x  5 root   root   4096 Sep 24 21:33 daily.1
drwxr-xr-x  4 root   root   4096 Sep 23 21:33 daily.2
drwxr-xr-x  4 root   root   4096 Sep 22 21:33 daily.3
drwxr-xr-x  4 root   root   4096 Sep 21 21:33 daily.4
drwxr-xr-x  4 root   root   4096 Sep 20 21:32 daily.5

Crontab

0,30 * * * * /usr/bin/rsnapshot halfhourly >> /var/log/rsnapshot.halfhourly.log 2>&1
5 * * * * /usr/bin/rsnapshot hourly >> /var/log/rsnapshot.hourly.log 2>&1
10 */2 * * * /usr/bin/rsnapshot twohourly >> /var/log/rsnapshot.twohourly.log 2>&1
15 3 * * * /usr/bin/rsnapshot daily >> /var/log/rsnapshot.daily.log 2>&1
20 6 * * MON /usr/bin/rsnapshot weekly >> /var/log/rsnapshot.weekly.log 2>&1

Weekly doesn't seem to work yet, but changing MON for 1 will probably fix it. two-hourly is not always every two hour

Best Answer

you have to understand how rsnapshot generates the backups.

First of all: Only the first interval you are defining takes the snapshot all other intervals just move old snapshots.

In your example:

interval halfhourly 4

first moves the old snapshots from halfhourly.n to halfhourly.n+1. Then it takes a new snapshot in halfhourly.0.

When you run the other jobs (hourly, twohourly, daily, weekly) they just take the last snapshot of the former job. So: hourly.4 is moved to twohourly.0 twohourly.24 is moved to daily.0 daily.7 is moved to weekly.0

This explains why the timestamp of the snapshot is always .32. Because it is actually a "halfhourly" snapshot that was moved to "hourly".

Hope that helps, Alex