linux cron: want to backup a folder

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
5
down vote

favorite
2












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.










share|improve this question















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 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














up vote
5
down vote

favorite
2












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.










share|improve this question















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 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












up vote
5
down vote

favorite
2









up vote
5
down vote

favorite
2






2





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.










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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
















  • 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















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










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 





share|improve this answer




















  • 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

















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/





share|improve this answer
















  • 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 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

















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





share|improve this answer




















    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    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

























    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 





    share|improve this answer




















    • 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














    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 





    share|improve this answer




















    • 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












    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 





    share|improve this answer












    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 






    share|improve this answer












    share|improve this answer



    share|improve this answer










    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
















    • 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












    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/





    share|improve this answer
















    • 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 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














    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/





    share|improve this answer
















    • 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 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












    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/





    share|improve this answer












    $ 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/






    share|improve this answer












    share|improve this answer



    share|improve this answer










    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 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












    • 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 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







    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










    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





    share|improve this answer
























      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





      share|improve this answer






















        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





        share|improve this answer












        Use command crontab -e and add this line to your crontab:



        0 13 * * 2 cp -pra /usr/local/src/djcode/c2duo_mms /home/sh






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jul 19 '11 at 10:53









        Janne Pikkarainen

        29514




        29514



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            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





















































            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






            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?