2
I'm writing a command for cron
to do automatic backups for my flashdrive.
I use tar ... -N <some date>
to make the backup.
The issue is how to write the command which gives me the right date.
For weekly backup I thought about:
date -d '1 week ago' +%Y%m%d
date -d 'monday week ago' +%Y%m%d
But it gets complicated when when my laptop is turned off on the cron scheduled time (monday after). Let's say anacron pick up the job on Tuesday. With the first variant I miss all changes from previous Monday. The second variant misses the whole previous week.
date -d 'monday 1 week ago' +%Y%m%d
is the same as date -d 'monday week ago' +%Y%m%d
date -d 'monday 2 week ago' +%Y%m%d
is correct in the case when backup is made by anacron, but it has one week extra in (the regular case) of cron.
Any idea, how could I make the backup time anacron compatible?