linux cron: want to backup a folder
Clash Royale CLAN TAG#URR8PPP
up vote
5
down vote
favorite
I would like to backup a folder using cron on a centos. The folder c2duo_mms
is located in /usr/local/src/djcode/c2duo_mms
. I would like it backed ip every 1:00pm on Tuedays to my home folder /home/sh
.
backup cron
migrated from serverfault.com Jul 19 '11 at 11:03
This question came from our site for system and network administrators.
add a comment |
up vote
5
down vote
favorite
I would like to backup a folder using cron on a centos. The folder c2duo_mms
is located in /usr/local/src/djcode/c2duo_mms
. I would like it backed ip every 1:00pm on Tuedays to my home folder /home/sh
.
backup cron
migrated from serverfault.com Jul 19 '11 at 11:03
This question came from our site for system and network administrators.
Are you backing up a folder or a file? Your question has contradictory bits. For a single filecp
is fine, for a directoryrsync
is a better too. Please fix your question to get a precise answer.
– Caleb
Jul 19 '11 at 10:53
@Calebc2duo_mms
it is a folder -- fixed
– Shehzad009
Jul 19 '11 at 10:57
add a comment |
up vote
5
down vote
favorite
up vote
5
down vote
favorite
I would like to backup a folder using cron on a centos. The folder c2duo_mms
is located in /usr/local/src/djcode/c2duo_mms
. I would like it backed ip every 1:00pm on Tuedays to my home folder /home/sh
.
backup cron
I would like to backup a folder using cron on a centos. The folder c2duo_mms
is located in /usr/local/src/djcode/c2duo_mms
. I would like it backed ip every 1:00pm on Tuedays to my home folder /home/sh
.
backup cron
backup cron
edited Nov 17 at 0:32
Rui F Ribeiro
38.2k1475123
38.2k1475123
asked Jul 19 '11 at 10:46
Shehzad009
165128
165128
migrated from serverfault.com Jul 19 '11 at 11:03
This question came from our site for system and network administrators.
migrated from serverfault.com Jul 19 '11 at 11:03
This question came from our site for system and network administrators.
Are you backing up a folder or a file? Your question has contradictory bits. For a single filecp
is fine, for a directoryrsync
is a better too. Please fix your question to get a precise answer.
– Caleb
Jul 19 '11 at 10:53
@Calebc2duo_mms
it is a folder -- fixed
– Shehzad009
Jul 19 '11 at 10:57
add a comment |
Are you backing up a folder or a file? Your question has contradictory bits. For a single filecp
is fine, for a directoryrsync
is a better too. Please fix your question to get a precise answer.
– Caleb
Jul 19 '11 at 10:53
@Calebc2duo_mms
it is a folder -- fixed
– Shehzad009
Jul 19 '11 at 10:57
Are you backing up a folder or a file? Your question has contradictory bits. For a single file
cp
is fine, for a directory rsync
is a better too. Please fix your question to get a precise answer.– Caleb
Jul 19 '11 at 10:53
Are you backing up a folder or a file? Your question has contradictory bits. For a single file
cp
is fine, for a directory rsync
is a better too. Please fix your question to get a precise answer.– Caleb
Jul 19 '11 at 10:53
@Caleb
c2duo_mms
it is a folder -- fixed– Shehzad009
Jul 19 '11 at 10:57
@Caleb
c2duo_mms
it is a folder -- fixed– Shehzad009
Jul 19 '11 at 10:57
add a comment |
3 Answers
3
active
oldest
votes
up vote
9
down vote
accepted
A good thing to do would be to create a new compressed archive in your home.
Create this script named for exmaple */home/sh/c2duo_mms_backup.sh*:
#!/bin/bash
cd /usr/local/src/djcode/
tar zcf /home/sh/c2duo_mms-`date +%Y%m%d`.tar.gz c2duo_mms
Be sure to add the executable permission to the script:
chmod +x /home/sh/c2duo_mms_backup.sh
Then add the relevant crontab entry with the crontab -e command:
0 13 * * 2 /home/sh/c2duo_mms_backup.sh
The script will create a new compressed archive every Tuesday with the date in the filename, so that you can keep older backups if you want. File name will look like this:
c2duo_mms_20110719.tar.gz
This is what I have been looking for!!! thanks a lot.
– Shehzad009
Jul 19 '11 at 12:41
a better solution would be to use rsync or unison.
– symcbean
Jul 19 '11 at 14:58
add a comment |
up vote
3
down vote
$ crontab -e
0 13 * * 2 cp -b /usr/local/src/djcode/c2duo_mms /home/sh/
The crontab -e
command should pull up the crontab file for editing in your preferred editor (Set by the EDITOR or VISUAL environment variabels). The crontab line says to run the command on the 0th minute, 13th hour, 2nd day of the week, any day of the month any year. The command itself is a simple single file copy, except that I added the -b
argument so that cp
makes a backup file. This should leave you with TWO backups at all times, the current one and the previous one (with a .bk extension).
Edit: For a folder instead of a file, try rsync
:
0 13 * * 2 rsync -av /usr/local/src/djcode/c2duo_mms/ /home/sh/c2duo_mms/
1
That would be "perform this on the second day of every month at 1am", right?
– Janne Pikkarainen
Jul 19 '11 at 10:54
@caleb: For some reason it is not copying the folder to my home directory. Is there like some way that I can find what is causing this problem?
– Shehzad009
Jul 19 '11 at 11:25
@Shehzad009: If you are using the rsync, you might make sure the target folder exists first before syncing it. Some will create it, but some won't. Also, to debug this, run th rsyncs e command manually yourself instead of from cron to see the output and make sure the backup part does what you want before sticking it in cron.
– Caleb
Jul 19 '11 at 11:27
@caleb: After usingrsync e
I get this"/home/sh/e" failed: No such file or directory (2)
. Not so sure what that e is.
– Shehzad009
Jul 19 '11 at 11:33
Thee
is a bogus typo on your end somewhere, it doesn't appear in the command I suggested. The syntax isrsync -[options] [source] [target]
, and it's important to end with trailing slashes on the source and targets if you are syncing directories.
– Caleb
Jul 19 '11 at 11:36
add a comment |
up vote
2
down vote
Use command crontab -e
and add this line to your crontab:
0 13 * * 2 cp -pra /usr/local/src/djcode/c2duo_mms /home/sh
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
9
down vote
accepted
A good thing to do would be to create a new compressed archive in your home.
Create this script named for exmaple */home/sh/c2duo_mms_backup.sh*:
#!/bin/bash
cd /usr/local/src/djcode/
tar zcf /home/sh/c2duo_mms-`date +%Y%m%d`.tar.gz c2duo_mms
Be sure to add the executable permission to the script:
chmod +x /home/sh/c2duo_mms_backup.sh
Then add the relevant crontab entry with the crontab -e command:
0 13 * * 2 /home/sh/c2duo_mms_backup.sh
The script will create a new compressed archive every Tuesday with the date in the filename, so that you can keep older backups if you want. File name will look like this:
c2duo_mms_20110719.tar.gz
This is what I have been looking for!!! thanks a lot.
– Shehzad009
Jul 19 '11 at 12:41
a better solution would be to use rsync or unison.
– symcbean
Jul 19 '11 at 14:58
add a comment |
up vote
9
down vote
accepted
A good thing to do would be to create a new compressed archive in your home.
Create this script named for exmaple */home/sh/c2duo_mms_backup.sh*:
#!/bin/bash
cd /usr/local/src/djcode/
tar zcf /home/sh/c2duo_mms-`date +%Y%m%d`.tar.gz c2duo_mms
Be sure to add the executable permission to the script:
chmod +x /home/sh/c2duo_mms_backup.sh
Then add the relevant crontab entry with the crontab -e command:
0 13 * * 2 /home/sh/c2duo_mms_backup.sh
The script will create a new compressed archive every Tuesday with the date in the filename, so that you can keep older backups if you want. File name will look like this:
c2duo_mms_20110719.tar.gz
This is what I have been looking for!!! thanks a lot.
– Shehzad009
Jul 19 '11 at 12:41
a better solution would be to use rsync or unison.
– symcbean
Jul 19 '11 at 14:58
add a comment |
up vote
9
down vote
accepted
up vote
9
down vote
accepted
A good thing to do would be to create a new compressed archive in your home.
Create this script named for exmaple */home/sh/c2duo_mms_backup.sh*:
#!/bin/bash
cd /usr/local/src/djcode/
tar zcf /home/sh/c2duo_mms-`date +%Y%m%d`.tar.gz c2duo_mms
Be sure to add the executable permission to the script:
chmod +x /home/sh/c2duo_mms_backup.sh
Then add the relevant crontab entry with the crontab -e command:
0 13 * * 2 /home/sh/c2duo_mms_backup.sh
The script will create a new compressed archive every Tuesday with the date in the filename, so that you can keep older backups if you want. File name will look like this:
c2duo_mms_20110719.tar.gz
A good thing to do would be to create a new compressed archive in your home.
Create this script named for exmaple */home/sh/c2duo_mms_backup.sh*:
#!/bin/bash
cd /usr/local/src/djcode/
tar zcf /home/sh/c2duo_mms-`date +%Y%m%d`.tar.gz c2duo_mms
Be sure to add the executable permission to the script:
chmod +x /home/sh/c2duo_mms_backup.sh
Then add the relevant crontab entry with the crontab -e command:
0 13 * * 2 /home/sh/c2duo_mms_backup.sh
The script will create a new compressed archive every Tuesday with the date in the filename, so that you can keep older backups if you want. File name will look like this:
c2duo_mms_20110719.tar.gz
answered Jul 19 '11 at 12:10
user842313
20612
20612
This is what I have been looking for!!! thanks a lot.
– Shehzad009
Jul 19 '11 at 12:41
a better solution would be to use rsync or unison.
– symcbean
Jul 19 '11 at 14:58
add a comment |
This is what I have been looking for!!! thanks a lot.
– Shehzad009
Jul 19 '11 at 12:41
a better solution would be to use rsync or unison.
– symcbean
Jul 19 '11 at 14:58
This is what I have been looking for!!! thanks a lot.
– Shehzad009
Jul 19 '11 at 12:41
This is what I have been looking for!!! thanks a lot.
– Shehzad009
Jul 19 '11 at 12:41
a better solution would be to use rsync or unison.
– symcbean
Jul 19 '11 at 14:58
a better solution would be to use rsync or unison.
– symcbean
Jul 19 '11 at 14:58
add a comment |
up vote
3
down vote
$ crontab -e
0 13 * * 2 cp -b /usr/local/src/djcode/c2duo_mms /home/sh/
The crontab -e
command should pull up the crontab file for editing in your preferred editor (Set by the EDITOR or VISUAL environment variabels). The crontab line says to run the command on the 0th minute, 13th hour, 2nd day of the week, any day of the month any year. The command itself is a simple single file copy, except that I added the -b
argument so that cp
makes a backup file. This should leave you with TWO backups at all times, the current one and the previous one (with a .bk extension).
Edit: For a folder instead of a file, try rsync
:
0 13 * * 2 rsync -av /usr/local/src/djcode/c2duo_mms/ /home/sh/c2duo_mms/
1
That would be "perform this on the second day of every month at 1am", right?
– Janne Pikkarainen
Jul 19 '11 at 10:54
@caleb: For some reason it is not copying the folder to my home directory. Is there like some way that I can find what is causing this problem?
– Shehzad009
Jul 19 '11 at 11:25
@Shehzad009: If you are using the rsync, you might make sure the target folder exists first before syncing it. Some will create it, but some won't. Also, to debug this, run th rsyncs e command manually yourself instead of from cron to see the output and make sure the backup part does what you want before sticking it in cron.
– Caleb
Jul 19 '11 at 11:27
@caleb: After usingrsync e
I get this"/home/sh/e" failed: No such file or directory (2)
. Not so sure what that e is.
– Shehzad009
Jul 19 '11 at 11:33
Thee
is a bogus typo on your end somewhere, it doesn't appear in the command I suggested. The syntax isrsync -[options] [source] [target]
, and it's important to end with trailing slashes on the source and targets if you are syncing directories.
– Caleb
Jul 19 '11 at 11:36
add a comment |
up vote
3
down vote
$ crontab -e
0 13 * * 2 cp -b /usr/local/src/djcode/c2duo_mms /home/sh/
The crontab -e
command should pull up the crontab file for editing in your preferred editor (Set by the EDITOR or VISUAL environment variabels). The crontab line says to run the command on the 0th minute, 13th hour, 2nd day of the week, any day of the month any year. The command itself is a simple single file copy, except that I added the -b
argument so that cp
makes a backup file. This should leave you with TWO backups at all times, the current one and the previous one (with a .bk extension).
Edit: For a folder instead of a file, try rsync
:
0 13 * * 2 rsync -av /usr/local/src/djcode/c2duo_mms/ /home/sh/c2duo_mms/
1
That would be "perform this on the second day of every month at 1am", right?
– Janne Pikkarainen
Jul 19 '11 at 10:54
@caleb: For some reason it is not copying the folder to my home directory. Is there like some way that I can find what is causing this problem?
– Shehzad009
Jul 19 '11 at 11:25
@Shehzad009: If you are using the rsync, you might make sure the target folder exists first before syncing it. Some will create it, but some won't. Also, to debug this, run th rsyncs e command manually yourself instead of from cron to see the output and make sure the backup part does what you want before sticking it in cron.
– Caleb
Jul 19 '11 at 11:27
@caleb: After usingrsync e
I get this"/home/sh/e" failed: No such file or directory (2)
. Not so sure what that e is.
– Shehzad009
Jul 19 '11 at 11:33
Thee
is a bogus typo on your end somewhere, it doesn't appear in the command I suggested. The syntax isrsync -[options] [source] [target]
, and it's important to end with trailing slashes on the source and targets if you are syncing directories.
– Caleb
Jul 19 '11 at 11:36
add a comment |
up vote
3
down vote
up vote
3
down vote
$ crontab -e
0 13 * * 2 cp -b /usr/local/src/djcode/c2duo_mms /home/sh/
The crontab -e
command should pull up the crontab file for editing in your preferred editor (Set by the EDITOR or VISUAL environment variabels). The crontab line says to run the command on the 0th minute, 13th hour, 2nd day of the week, any day of the month any year. The command itself is a simple single file copy, except that I added the -b
argument so that cp
makes a backup file. This should leave you with TWO backups at all times, the current one and the previous one (with a .bk extension).
Edit: For a folder instead of a file, try rsync
:
0 13 * * 2 rsync -av /usr/local/src/djcode/c2duo_mms/ /home/sh/c2duo_mms/
$ crontab -e
0 13 * * 2 cp -b /usr/local/src/djcode/c2duo_mms /home/sh/
The crontab -e
command should pull up the crontab file for editing in your preferred editor (Set by the EDITOR or VISUAL environment variabels). The crontab line says to run the command on the 0th minute, 13th hour, 2nd day of the week, any day of the month any year. The command itself is a simple single file copy, except that I added the -b
argument so that cp
makes a backup file. This should leave you with TWO backups at all times, the current one and the previous one (with a .bk extension).
Edit: For a folder instead of a file, try rsync
:
0 13 * * 2 rsync -av /usr/local/src/djcode/c2duo_mms/ /home/sh/c2duo_mms/
answered Jul 19 '11 at 10:52
Caleb
49.9k9146190
49.9k9146190
1
That would be "perform this on the second day of every month at 1am", right?
– Janne Pikkarainen
Jul 19 '11 at 10:54
@caleb: For some reason it is not copying the folder to my home directory. Is there like some way that I can find what is causing this problem?
– Shehzad009
Jul 19 '11 at 11:25
@Shehzad009: If you are using the rsync, you might make sure the target folder exists first before syncing it. Some will create it, but some won't. Also, to debug this, run th rsyncs e command manually yourself instead of from cron to see the output and make sure the backup part does what you want before sticking it in cron.
– Caleb
Jul 19 '11 at 11:27
@caleb: After usingrsync e
I get this"/home/sh/e" failed: No such file or directory (2)
. Not so sure what that e is.
– Shehzad009
Jul 19 '11 at 11:33
Thee
is a bogus typo on your end somewhere, it doesn't appear in the command I suggested. The syntax isrsync -[options] [source] [target]
, and it's important to end with trailing slashes on the source and targets if you are syncing directories.
– Caleb
Jul 19 '11 at 11:36
add a comment |
1
That would be "perform this on the second day of every month at 1am", right?
– Janne Pikkarainen
Jul 19 '11 at 10:54
@caleb: For some reason it is not copying the folder to my home directory. Is there like some way that I can find what is causing this problem?
– Shehzad009
Jul 19 '11 at 11:25
@Shehzad009: If you are using the rsync, you might make sure the target folder exists first before syncing it. Some will create it, but some won't. Also, to debug this, run th rsyncs e command manually yourself instead of from cron to see the output and make sure the backup part does what you want before sticking it in cron.
– Caleb
Jul 19 '11 at 11:27
@caleb: After usingrsync e
I get this"/home/sh/e" failed: No such file or directory (2)
. Not so sure what that e is.
– Shehzad009
Jul 19 '11 at 11:33
Thee
is a bogus typo on your end somewhere, it doesn't appear in the command I suggested. The syntax isrsync -[options] [source] [target]
, and it's important to end with trailing slashes on the source and targets if you are syncing directories.
– Caleb
Jul 19 '11 at 11:36
1
1
That would be "perform this on the second day of every month at 1am", right?
– Janne Pikkarainen
Jul 19 '11 at 10:54
That would be "perform this on the second day of every month at 1am", right?
– Janne Pikkarainen
Jul 19 '11 at 10:54
@caleb: For some reason it is not copying the folder to my home directory. Is there like some way that I can find what is causing this problem?
– Shehzad009
Jul 19 '11 at 11:25
@caleb: For some reason it is not copying the folder to my home directory. Is there like some way that I can find what is causing this problem?
– Shehzad009
Jul 19 '11 at 11:25
@Shehzad009: If you are using the rsync, you might make sure the target folder exists first before syncing it. Some will create it, but some won't. Also, to debug this, run th rsyncs e command manually yourself instead of from cron to see the output and make sure the backup part does what you want before sticking it in cron.
– Caleb
Jul 19 '11 at 11:27
@Shehzad009: If you are using the rsync, you might make sure the target folder exists first before syncing it. Some will create it, but some won't. Also, to debug this, run th rsyncs e command manually yourself instead of from cron to see the output and make sure the backup part does what you want before sticking it in cron.
– Caleb
Jul 19 '11 at 11:27
@caleb: After using
rsync e
I get this "/home/sh/e" failed: No such file or directory (2)
. Not so sure what that e is.– Shehzad009
Jul 19 '11 at 11:33
@caleb: After using
rsync e
I get this "/home/sh/e" failed: No such file or directory (2)
. Not so sure what that e is.– Shehzad009
Jul 19 '11 at 11:33
The
e
is a bogus typo on your end somewhere, it doesn't appear in the command I suggested. The syntax is rsync -[options] [source] [target]
, and it's important to end with trailing slashes on the source and targets if you are syncing directories.– Caleb
Jul 19 '11 at 11:36
The
e
is a bogus typo on your end somewhere, it doesn't appear in the command I suggested. The syntax is rsync -[options] [source] [target]
, and it's important to end with trailing slashes on the source and targets if you are syncing directories.– Caleb
Jul 19 '11 at 11:36
add a comment |
up vote
2
down vote
Use command crontab -e
and add this line to your crontab:
0 13 * * 2 cp -pra /usr/local/src/djcode/c2duo_mms /home/sh
add a comment |
up vote
2
down vote
Use command crontab -e
and add this line to your crontab:
0 13 * * 2 cp -pra /usr/local/src/djcode/c2duo_mms /home/sh
add a comment |
up vote
2
down vote
up vote
2
down vote
Use command crontab -e
and add this line to your crontab:
0 13 * * 2 cp -pra /usr/local/src/djcode/c2duo_mms /home/sh
Use command crontab -e
and add this line to your crontab:
0 13 * * 2 cp -pra /usr/local/src/djcode/c2duo_mms /home/sh
answered Jul 19 '11 at 10:53
Janne Pikkarainen
29514
29514
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f16947%2flinux-cron-want-to-backup-a-folder%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Are you backing up a folder or a file? Your question has contradictory bits. For a single file
cp
is fine, for a directoryrsync
is a better too. Please fix your question to get a precise answer.– Caleb
Jul 19 '11 at 10:53
@Caleb
c2duo_mms
it is a folder -- fixed– Shehzad009
Jul 19 '11 at 10:57