Crontab for an rsync backup with ssh connection

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








up vote
0
down vote

favorite












UBUNTU 16.04 Root Server.



I would like to have a crontab job run an rsync backup job every night at 2:14am.
It copies a "folder" from an Ubuntu 16.04 machine to another root server in the internet.
There is an ssh connection possible with a ssh key login.



The following command works in the terminal:




/usr/bin/rsync -az --delete -e ssh /home/user/folder/ user@server.example.com:/home/user/folder




But the following crontab job does not work:




14 2 * * * /usr/bin/rsync -az --delete -e ssh /home/user/folder/ user@server.example.com:/home/user/folder




I am having a hard time with crontab to be honest. It always feels to be a lucky situation if the job actually works.



Can someone see from the crontab job above what I am doing wrong?



greetings, Chris







share|improve this question
















  • 1




    What error does the command give when running from cron? 'does not work' is not enough.
    – Soren A
    May 15 at 8:17










  • I agree that this is not enough. But where could I see what error it gives? I have no idea where to see the error message, since it'sa a cronjob. And that runs "in the background" (if it runs).
    – StackChrisChris
    May 15 at 20:43










  • redirect the output from the command with > /path/to/outfile 2>&1 and check the content of the file after cron has run the job.
    – Soren A
    May 15 at 22:38










  • Thanks for that already!. I get the error message: Host key verification failed. rsync: connection unexpectedly closed (0 bytes received so far) [sender] rsync error: unexplained error (code 255) at io.c(226) [sender=3.1.1]
    – StackChrisChris
    May 16 at 8:56










  • I guess the Host Key error happens because it tries to connect as "root" and not as "user". I need to define the ssh user for the connection.
    – StackChrisChris
    May 16 at 9:02














up vote
0
down vote

favorite












UBUNTU 16.04 Root Server.



I would like to have a crontab job run an rsync backup job every night at 2:14am.
It copies a "folder" from an Ubuntu 16.04 machine to another root server in the internet.
There is an ssh connection possible with a ssh key login.



The following command works in the terminal:




/usr/bin/rsync -az --delete -e ssh /home/user/folder/ user@server.example.com:/home/user/folder




But the following crontab job does not work:




14 2 * * * /usr/bin/rsync -az --delete -e ssh /home/user/folder/ user@server.example.com:/home/user/folder




I am having a hard time with crontab to be honest. It always feels to be a lucky situation if the job actually works.



Can someone see from the crontab job above what I am doing wrong?



greetings, Chris







share|improve this question
















  • 1




    What error does the command give when running from cron? 'does not work' is not enough.
    – Soren A
    May 15 at 8:17










  • I agree that this is not enough. But where could I see what error it gives? I have no idea where to see the error message, since it'sa a cronjob. And that runs "in the background" (if it runs).
    – StackChrisChris
    May 15 at 20:43










  • redirect the output from the command with > /path/to/outfile 2>&1 and check the content of the file after cron has run the job.
    – Soren A
    May 15 at 22:38










  • Thanks for that already!. I get the error message: Host key verification failed. rsync: connection unexpectedly closed (0 bytes received so far) [sender] rsync error: unexplained error (code 255) at io.c(226) [sender=3.1.1]
    – StackChrisChris
    May 16 at 8:56










  • I guess the Host Key error happens because it tries to connect as "root" and not as "user". I need to define the ssh user for the connection.
    – StackChrisChris
    May 16 at 9:02












up vote
0
down vote

favorite









up vote
0
down vote

favorite











UBUNTU 16.04 Root Server.



I would like to have a crontab job run an rsync backup job every night at 2:14am.
It copies a "folder" from an Ubuntu 16.04 machine to another root server in the internet.
There is an ssh connection possible with a ssh key login.



The following command works in the terminal:




/usr/bin/rsync -az --delete -e ssh /home/user/folder/ user@server.example.com:/home/user/folder




But the following crontab job does not work:




14 2 * * * /usr/bin/rsync -az --delete -e ssh /home/user/folder/ user@server.example.com:/home/user/folder




I am having a hard time with crontab to be honest. It always feels to be a lucky situation if the job actually works.



Can someone see from the crontab job above what I am doing wrong?



greetings, Chris







share|improve this question












UBUNTU 16.04 Root Server.



I would like to have a crontab job run an rsync backup job every night at 2:14am.
It copies a "folder" from an Ubuntu 16.04 machine to another root server in the internet.
There is an ssh connection possible with a ssh key login.



The following command works in the terminal:




/usr/bin/rsync -az --delete -e ssh /home/user/folder/ user@server.example.com:/home/user/folder




But the following crontab job does not work:




14 2 * * * /usr/bin/rsync -az --delete -e ssh /home/user/folder/ user@server.example.com:/home/user/folder




I am having a hard time with crontab to be honest. It always feels to be a lucky situation if the job actually works.



Can someone see from the crontab job above what I am doing wrong?



greetings, Chris









share|improve this question











share|improve this question




share|improve this question










asked May 15 at 8:15









StackChrisChris

114




114







  • 1




    What error does the command give when running from cron? 'does not work' is not enough.
    – Soren A
    May 15 at 8:17










  • I agree that this is not enough. But where could I see what error it gives? I have no idea where to see the error message, since it'sa a cronjob. And that runs "in the background" (if it runs).
    – StackChrisChris
    May 15 at 20:43










  • redirect the output from the command with > /path/to/outfile 2>&1 and check the content of the file after cron has run the job.
    – Soren A
    May 15 at 22:38










  • Thanks for that already!. I get the error message: Host key verification failed. rsync: connection unexpectedly closed (0 bytes received so far) [sender] rsync error: unexplained error (code 255) at io.c(226) [sender=3.1.1]
    – StackChrisChris
    May 16 at 8:56










  • I guess the Host Key error happens because it tries to connect as "root" and not as "user". I need to define the ssh user for the connection.
    – StackChrisChris
    May 16 at 9:02












  • 1




    What error does the command give when running from cron? 'does not work' is not enough.
    – Soren A
    May 15 at 8:17










  • I agree that this is not enough. But where could I see what error it gives? I have no idea where to see the error message, since it'sa a cronjob. And that runs "in the background" (if it runs).
    – StackChrisChris
    May 15 at 20:43










  • redirect the output from the command with > /path/to/outfile 2>&1 and check the content of the file after cron has run the job.
    – Soren A
    May 15 at 22:38










  • Thanks for that already!. I get the error message: Host key verification failed. rsync: connection unexpectedly closed (0 bytes received so far) [sender] rsync error: unexplained error (code 255) at io.c(226) [sender=3.1.1]
    – StackChrisChris
    May 16 at 8:56










  • I guess the Host Key error happens because it tries to connect as "root" and not as "user". I need to define the ssh user for the connection.
    – StackChrisChris
    May 16 at 9:02







1




1




What error does the command give when running from cron? 'does not work' is not enough.
– Soren A
May 15 at 8:17




What error does the command give when running from cron? 'does not work' is not enough.
– Soren A
May 15 at 8:17












I agree that this is not enough. But where could I see what error it gives? I have no idea where to see the error message, since it'sa a cronjob. And that runs "in the background" (if it runs).
– StackChrisChris
May 15 at 20:43




I agree that this is not enough. But where could I see what error it gives? I have no idea where to see the error message, since it'sa a cronjob. And that runs "in the background" (if it runs).
– StackChrisChris
May 15 at 20:43












redirect the output from the command with > /path/to/outfile 2>&1 and check the content of the file after cron has run the job.
– Soren A
May 15 at 22:38




redirect the output from the command with > /path/to/outfile 2>&1 and check the content of the file after cron has run the job.
– Soren A
May 15 at 22:38












Thanks for that already!. I get the error message: Host key verification failed. rsync: connection unexpectedly closed (0 bytes received so far) [sender] rsync error: unexplained error (code 255) at io.c(226) [sender=3.1.1]
– StackChrisChris
May 16 at 8:56




Thanks for that already!. I get the error message: Host key verification failed. rsync: connection unexpectedly closed (0 bytes received so far) [sender] rsync error: unexplained error (code 255) at io.c(226) [sender=3.1.1]
– StackChrisChris
May 16 at 8:56












I guess the Host Key error happens because it tries to connect as "root" and not as "user". I need to define the ssh user for the connection.
– StackChrisChris
May 16 at 9:02




I guess the Host Key error happens because it tries to connect as "root" and not as "user". I need to define the ssh user for the connection.
– StackChrisChris
May 16 at 9:02










1 Answer
1






active

oldest

votes

















up vote
1
down vote













The problem I had was that the ssh connection
The Host Key verification failed.



I ran the cronjob on the crontab of root.
(I added the cronjob via "sudo crontab -e".)




14 2 * * * /usr/bin/rsync -az --delete -e ssh /home/user/folder/ user@server.example.com:/home/user/folder




It seems that the ssh connection then is established by the root user and not by the "user".



So the connection attempt is actually:




ssh root@server.example.com




and not




ssh user@server.example.com




So I added the cronjob to the crontab of the "user".
(crontab -e (without sudo)).



Now the Host Key Verification works and the crontab rsync job is executed properly.



I don't know exactly if the above assumptions are correct but this solved the problem.



I hope this thread will help someone else at some stage as well.



Greetings, Chris






share|improve this answer




















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "89"
    ;
    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: true,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );








     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1036421%2fcrontab-for-an-rsync-backup-with-ssh-connection%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    The problem I had was that the ssh connection
    The Host Key verification failed.



    I ran the cronjob on the crontab of root.
    (I added the cronjob via "sudo crontab -e".)




    14 2 * * * /usr/bin/rsync -az --delete -e ssh /home/user/folder/ user@server.example.com:/home/user/folder




    It seems that the ssh connection then is established by the root user and not by the "user".



    So the connection attempt is actually:




    ssh root@server.example.com




    and not




    ssh user@server.example.com




    So I added the cronjob to the crontab of the "user".
    (crontab -e (without sudo)).



    Now the Host Key Verification works and the crontab rsync job is executed properly.



    I don't know exactly if the above assumptions are correct but this solved the problem.



    I hope this thread will help someone else at some stage as well.



    Greetings, Chris






    share|improve this answer
























      up vote
      1
      down vote













      The problem I had was that the ssh connection
      The Host Key verification failed.



      I ran the cronjob on the crontab of root.
      (I added the cronjob via "sudo crontab -e".)




      14 2 * * * /usr/bin/rsync -az --delete -e ssh /home/user/folder/ user@server.example.com:/home/user/folder




      It seems that the ssh connection then is established by the root user and not by the "user".



      So the connection attempt is actually:




      ssh root@server.example.com




      and not




      ssh user@server.example.com




      So I added the cronjob to the crontab of the "user".
      (crontab -e (without sudo)).



      Now the Host Key Verification works and the crontab rsync job is executed properly.



      I don't know exactly if the above assumptions are correct but this solved the problem.



      I hope this thread will help someone else at some stage as well.



      Greetings, Chris






      share|improve this answer






















        up vote
        1
        down vote










        up vote
        1
        down vote









        The problem I had was that the ssh connection
        The Host Key verification failed.



        I ran the cronjob on the crontab of root.
        (I added the cronjob via "sudo crontab -e".)




        14 2 * * * /usr/bin/rsync -az --delete -e ssh /home/user/folder/ user@server.example.com:/home/user/folder




        It seems that the ssh connection then is established by the root user and not by the "user".



        So the connection attempt is actually:




        ssh root@server.example.com




        and not




        ssh user@server.example.com




        So I added the cronjob to the crontab of the "user".
        (crontab -e (without sudo)).



        Now the Host Key Verification works and the crontab rsync job is executed properly.



        I don't know exactly if the above assumptions are correct but this solved the problem.



        I hope this thread will help someone else at some stage as well.



        Greetings, Chris






        share|improve this answer












        The problem I had was that the ssh connection
        The Host Key verification failed.



        I ran the cronjob on the crontab of root.
        (I added the cronjob via "sudo crontab -e".)




        14 2 * * * /usr/bin/rsync -az --delete -e ssh /home/user/folder/ user@server.example.com:/home/user/folder




        It seems that the ssh connection then is established by the root user and not by the "user".



        So the connection attempt is actually:




        ssh root@server.example.com




        and not




        ssh user@server.example.com




        So I added the cronjob to the crontab of the "user".
        (crontab -e (without sudo)).



        Now the Host Key Verification works and the crontab rsync job is executed properly.



        I don't know exactly if the above assumptions are correct but this solved the problem.



        I hope this thread will help someone else at some stage as well.



        Greetings, Chris







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered May 16 at 11:02









        StackChrisChris

        114




        114






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1036421%2fcrontab-for-an-rsync-backup-with-ssh-connection%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How do so many people here on Academia.SE, and in general, afford lavish higher education programs?

            Trouble downloading packages list due to a “Hash sum mismatch” error

            How do I move numbers in filenames, in a batch renaming operation?