lundi 31 août 2015

cronjob to remove file where the name contains the date of 7 days ago

I have created a cronjob to backup a database into a sql file with a date in the file name:

5 0,10,15,20 * * * /usr/syno/mysql/bin/mysqldump -u<user> -p<password> --opt DATABASE > "/volume5/DATABASE$(date +\%F).sql"`

I am trying to have an other cronjob to delete the file of 7 days ago

0 0 * * * rm /volume5/DATABASE$(/bin/date -D "%s" -d $(( $(/bin/date +\%s ) - 604800 )) +\%F).sql

for example, if the actual date is 2015-08-31, the file of 7 days ago is DATABASE2015-08-24.sql, which should be deleted.

the removal does not work by cron, but does by manual command, so I guess it is only a missing "escape", but I can't figure out where.

Does anybody know where is the problem ?

The "X days ago" option does not work with this date bin.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire