System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

help me take backup using cron

SOLVED
Go to solution
Maaz
Valued Contributor

help me take backup using cron

I can create a backup as
#tar -cvf /var/"$(date +%F)"_tmp.tar /tmp

but cant take backup when using cron
#crontab -e
05 21 * * * /bin/tar -cf /var/"$(date +%F)"_tmp.tar /tmp

why ?
plz help
Regards
1 REPLY
Steven E. Protter
Exalted Contributor
Solution

Re: help me take backup using cron

Shalom Maaz,

You are missing the basic idea of cron. No environment. No path, no nothing. The date command probably failed.

There is a cron log in /var/logs

Take this code adn put it int a shell script.

Example:

05 21 * * * /usr/contrib/bin/mybackup > /dev/null

Script:
#!/bin/sh
# set PATH and such so it works.

backkupfilename="/var/$(date +%F)_tmp.tar"
/bin/tar -cvf $backupfilename /tmp

Cron is not the command line. testing it on the command line is useless.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com