WebFaction
Community site: login faq

I followed the webfaction guide to setup a db backup. This works well and outputs a filename with the date: db_bkup-date +\%Y\%m\%d.sql. But if I set the cron to run at UTC 0200, then on the 6th it output the filename as the 6th, but its actually 2100 on the 5th CST, which is the timezone of my app. How would I modify the output to say one day earlier (since this db backup will be a backup at end of the day on the 5th in my app's timezone?)

asked 06 Feb '14, 01:32

rsp
141612
accept rate: 0%


Hello,

date -d "$(date +%Y-%m-%d) -1 day" +"%Y-%m-%d"

is what you are looking for. You make 'date' display the current date minus one day:

-d "$(date +%Y-%m-%d) -1 day"

and then you specify the format. By the way, you can specify -1 week, -1 month and so on. Positive time periods also work (e.g. 1 day, 1 week, etc.).

See http://linux.die.net/man/1/date for more information.

Sincerely,

Valentin I.
WebFaction Support
--
WebFaction - Smarter web hosting
http://webfaction.com
http://twitter.com/webfaction - http://facebook.com/webfaction

permanent link

answered 06 Feb '14, 12:37

valentini
2614
accept rate: 28%

@valentini, Thanks, this works when I type it in manually. However, once I put the same line in the crontab I get: /bin/sh: -c: line 0: unexpected EOF while looking for matching ``' /bin/sh: -c: line 1: syntax error: unexpected end of file

I copied what I have in the contab exactly to the command line and ran it and it worked: mysqldump --defaults-file=$HOME/db_backups/live/some_db.cnf -u some_db some_db > $HOME/db_backups/live/backups/some_db_live_bkup-date -d "$(date +%Y-%m-%d) -1 day" +"%Y-%m-%d".sql

(09 Feb '14, 14:09) rsp

Try placing the code within a shell script and than executing it with cron.

(10 Feb '14, 02:55) johns

@johns, that worked. thanks.

(10 Feb '14, 08:47) rsp
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×81
×22
×16

question asked: 06 Feb '14, 01:32

question was seen: 1,355 times

last updated: 10 Feb '14, 08:47

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM