cron

  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

Well the more development I do on my server the more I want to start to make some backups. This is my current cron command I'm running

Code: [ Select ]
0 3 * * * root tar -czf /home/travis/.backups/sites.tar.gz /home/travis/sites >> /dev/null 2>&1


However, I was wondering how I could make the file name into a dynamic date instead of the static name now.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

Something like this maybe ?

Code: [ Select ]
tar -czf "/home/travis/.backups/`date +%Y-%m-%d_%H-%M-%S`.tar.gz" /home/travis/sites
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

I'll give it a try, I changed the time so it should exicute in about a minute or two.

When I change a value in my crontab do I need to reload something for it to take effect?

//Update: well I set it back to how I had it with the static and it worked so I guess I dont have to reload anything. Just looks like it didnt like the date syntax.
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

Okay, found out the problem

Here is a rework of the example Joe gave.

Code: [ Select ]
tar -czf "/home/travis/.backups/$(date \+\%Y-\%m-\%d_\%H-\%M-\%S).tar.gz" /home/travis/sites


That should work, however I didnt try that format. Just $(date \+\%a) which creates a file of the format Sun.tar.gz, Mon.tar.gz and so on.
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

That looks good. Gives you a weeks worth of backups & they'll overwrite themselves. :D

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 22 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.