Crontab for an rsync backup with ssh connection

Clash 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
cron rsync
 |Â
show 3 more comments
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
cron rsync
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>&1and 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
 |Â
show 3 more comments
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
cron rsync
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
cron rsync
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>&1and 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
 |Â
show 3 more comments
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>&1and 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
 |Â
show 3 more comments
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
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
answered May 16 at 11:02
StackChrisChris
114
114
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
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
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>&1and 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