Jacob Valenta
Jacob Valenta

Reputation: 6769

Simple Cronjob to backup a directory

I know this seems pretty trivial but I can't see to get this to work in cronjob.

I am running

zip -r /backup/$(date +'%Y%m%d').zip /var/www

This works fine. It gives me zip file in my backup directory.

But I will open Cron tab with

crontab -e

And I append this to the bottom of the file so it does daily updates.

This is where it doesn't work.

What am I doing wrong?

Edit: crontab looks like

0 1 * * * /home/serveradmin/backup.sh

Upvotes: 4

Views: 10814

Answers (1)

user4262745
user4262745

Reputation: 66

In cron the % (percent) sign needs to be escaped. You should comment out the percent signs with a \ (backslash) in front of them. i.e.,

date +\%Y-\%m-\%d-\%H-\%M

Upvotes: 5

Related Questions