LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-18-2012, 06:29 PM   #16
ASTRAPI
Member
 
Registered: Feb 2007
Posts: 210

Original Poster
Rep: Reputation: 16

Ok i will test it as:

Code:
0 5 * * * cd /home; /usr/bin/mysqldump -u root -h localhost -pmypasshere dbname | gzip > mydatabase-$(date +\%d-\%m-\%Y).sql.gzip
but what i can do with the other command?

Code:
20 5 * * * cd /home; tar -zcf backup_files_$(date +\%d-\%m-\%Y).tgz /home/nginx/domains/mydomain.com/public/
 
Old 03-18-2012, 06:56 PM   #17
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,417

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
As recommended by ac_kumar, don't put complex cmds in cron.
Put them in a file eg /home/me/mybackup.sh, and call that from cron.
As also recommended above, re-direct outputs to a file to help with debugging eg
Code:
20 5 * * * /home/me/mybackup.sh >/home/me/mybackup.log 2>&1
Finally (as above), cron has a limited cmd PATH, so always use the full absolute path to any cmds or set the desired PATH as the first cmd in the shell script.
http://www.adminschoice.com/crontab-quick-reference
 
Old 03-18-2012, 07:30 PM   #18
ASTRAPI
Member
 
Registered: Feb 2007
Posts: 210

Original Poster
Rep: Reputation: 16
Ok i will create a file mybackup.sh and i will place it on my /home/ directory (i want there to place also my backups)and i will run to it:

Code:
chmod +x mybackup.sh
Then i will add on crontab this:
Code:
20 5 * * * /home/mybackup.sh >/home/mybackup.log 2>&1
But now which lines to use?
Code:
0 5 * * * cd /home; mysqldump -u root -h localhost -pmypasshere dbname | gzip > mydatabase-$(date +%d-%m-%Y).sql.gzip >/dev/null 2>&1
20 5 * * * cd /home; tar -zcf backup_files_$(date +\%d-\%m-\%Y).tgz /home/nginx/domains/mydomain.com/public/ >/dev/null 2>&1
or
Code:
0 5 * * * cd /home; mysqldump -u root -h localhost -pmypasshere dbname | gzip > mydatabase-$(date +\%d-\%m-\%Y).sql.gzip
20 5 * * * cd /home; tar -zcf backup_files_$(date +\%d-\%m-\%Y).tgz /home/nginx/domains/mydomain.com/public/
or
Code:
0 5 * * * cd /home; /usr/bin/mysqldump -u root -h localhost -pmypasshere dbname | gzip > mydatabase-$(date +\%d-\%m-\%Y).sql.gzip
20 5 * * * cd /home; tar -zcf backup_files_$(date +\%d-\%m-\%Y).tgz /home/nginx/domains/mydomain.com/public/
or i must add on the last commands also the 2>&1 at the end?

Do i have to add anything else on the mybackup.sh other than those two lines?


What do you think about this content of mybackup.sh?

Code:
#!/bin/sh
cd /home/

/usr/bin/mysqldump -u root -h localhost -pmypasshere dbname | gzip > mydatabase-$(date +\%d-\%m-\%Y).sql.gzip

tar -zcf backup_files_$(date +\%d-\%m-\%Y).tgz /home/nginx/domains/mydomain.com/public/
Thank you

Last edited by ASTRAPI; 03-18-2012 at 07:37 PM.
 
Old 03-18-2012, 07:59 PM   #19
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,417

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
Code:
20 5 * * * /home/mybackup.sh >/home/mybackup.log 2>&1
This is sufficient. Just put the relevant cmds inside; they don't need cron settings as they are not being run by cron; the enclosing shell file is...

I also recommend you start by putting some simple cmds in there instead of backup ones and play with it until you understand cron.
Note my 2nd comment above about using full absolute paths to cmds or setting the the PATH at the top of the script.

Have a good read of the links about cron that have been supplied.
 
Old 03-18-2012, 08:21 PM   #20
ASTRAPI
Member
 
Registered: Feb 2007
Posts: 210

Original Poster
Rep: Reputation: 16
Ok i fix it thanks all of you
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
CentOS 5.4 64bit php-gd issue Nicarlo Linux - Newbie 4 03-11-2012 03:53 PM
Install mplayer on Centos 6.0 64bit? rewards Linux - Software 13 01-04-2012 03:57 AM
libgaim.so.0()(64bit) error | centos Cheza Linux - General 1 01-12-2008 11:32 AM
Wireshark Install On CentOS 64bit krams Linux - Newbie 3 04-24-2007 05:35 PM
What is the best way to do a scripted, cronjob, backup? Mikey_GoEagles Linux - General 3 12-02-2005 10:35 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration