Trying to create a cron to Rsync then tar the folder
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I'm stuck at the first hurdle!
I want to run a couple of commands from a bash script. First something like this to rsync some directories:
rsync -e ssh -az user-whatever@website.com:/home /location/of/local/folder
Then something like this to tar and copy the files somewhere else:
cd /location/of/local/folder
tar zcf /var/backups/home-`date +%Y%m%d`.tar.gz home
I hope this is making sense.
The problem is that obviously I wish for the rsync to finish before the directory is tar'd. So is there a bit of code I can use to make sure that rsync has finished before running the tar command?
e.g. (pseudo code)
rsync
while(is syncing){
sleep 10
}
tar
Or will my .sh script only run the next line after the first line has finished and exited?
shell-script cron rsync
add a comment |
I'm stuck at the first hurdle!
I want to run a couple of commands from a bash script. First something like this to rsync some directories:
rsync -e ssh -az user-whatever@website.com:/home /location/of/local/folder
Then something like this to tar and copy the files somewhere else:
cd /location/of/local/folder
tar zcf /var/backups/home-`date +%Y%m%d`.tar.gz home
I hope this is making sense.
The problem is that obviously I wish for the rsync to finish before the directory is tar'd. So is there a bit of code I can use to make sure that rsync has finished before running the tar command?
e.g. (pseudo code)
rsync
while(is syncing){
sleep 10
}
tar
Or will my .sh script only run the next line after the first line has finished and exited?
shell-script cron rsync
add a comment |
I'm stuck at the first hurdle!
I want to run a couple of commands from a bash script. First something like this to rsync some directories:
rsync -e ssh -az user-whatever@website.com:/home /location/of/local/folder
Then something like this to tar and copy the files somewhere else:
cd /location/of/local/folder
tar zcf /var/backups/home-`date +%Y%m%d`.tar.gz home
I hope this is making sense.
The problem is that obviously I wish for the rsync to finish before the directory is tar'd. So is there a bit of code I can use to make sure that rsync has finished before running the tar command?
e.g. (pseudo code)
rsync
while(is syncing){
sleep 10
}
tar
Or will my .sh script only run the next line after the first line has finished and exited?
shell-script cron rsync
I'm stuck at the first hurdle!
I want to run a couple of commands from a bash script. First something like this to rsync some directories:
rsync -e ssh -az user-whatever@website.com:/home /location/of/local/folder
Then something like this to tar and copy the files somewhere else:
cd /location/of/local/folder
tar zcf /var/backups/home-`date +%Y%m%d`.tar.gz home
I hope this is making sense.
The problem is that obviously I wish for the rsync to finish before the directory is tar'd. So is there a bit of code I can use to make sure that rsync has finished before running the tar command?
e.g. (pseudo code)
rsync
while(is syncing){
sleep 10
}
tar
Or will my .sh script only run the next line after the first line has finished and exited?
shell-script cron rsync
shell-script cron rsync
edited 1 hour ago
Rui F Ribeiro
41.9k1483142
41.9k1483142
asked May 4 '12 at 16:01
Thomas ClaysonThomas Clayson
240212
240212
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Commands in a shell script are executed sequentially. If your first command is rsync, the next command will not execute until rsync completes.
What you want to be sure of is that rsync finishes successfully before continuing to the next command.
This is not the most elegant solution, but the easiest to implement.
rsync -e ssh -az user-whatever@website.com:/home /location/of/local/folder &&
tar zcf /var/backups/home-`date +%Y%m%d`.tar.gz /location/of/local/folder
Keep in mind this will only work if the exit status of rsync is 0. Any other exit status and command 2 will not run.
AND and OR lists are sequences of one of more pipelines separated by the &&
and || control operators, respectively. AND and OR lists are executed
with left associativity. An AND list has the form
command1 && command2
command2 is executed if, and only if, command1 returns an exit status of zero.
You could add more intelligence to your script if you performed different actions based on the rsync EXIT VALUES.
#!/bin/bash
PATH=/bin:/usr/bin:/sbin:/usr/sbin
rsync -e ssh -az user-whatever@website.com:/home /location/of/local/folder
if [ $? != "0" ]
then
echo "There was a problem"
else
tar zcf /var/backups/home-`date +%Y%m%d`.tar.gz /location/of/local/folder
fi
This is a brilliant and insightful answer. Thank you very much for taking the time. :) You've really helped me. Thank you.
– Thomas Clayson
May 8 '12 at 8:14
add a comment |
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',
autoActivateHeartbeat: false,
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
});
}
});
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%2f37912%2ftrying-to-create-a-cron-to-rsync-then-tar-the-folder%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Commands in a shell script are executed sequentially. If your first command is rsync, the next command will not execute until rsync completes.
What you want to be sure of is that rsync finishes successfully before continuing to the next command.
This is not the most elegant solution, but the easiest to implement.
rsync -e ssh -az user-whatever@website.com:/home /location/of/local/folder &&
tar zcf /var/backups/home-`date +%Y%m%d`.tar.gz /location/of/local/folder
Keep in mind this will only work if the exit status of rsync is 0. Any other exit status and command 2 will not run.
AND and OR lists are sequences of one of more pipelines separated by the &&
and || control operators, respectively. AND and OR lists are executed
with left associativity. An AND list has the form
command1 && command2
command2 is executed if, and only if, command1 returns an exit status of zero.
You could add more intelligence to your script if you performed different actions based on the rsync EXIT VALUES.
#!/bin/bash
PATH=/bin:/usr/bin:/sbin:/usr/sbin
rsync -e ssh -az user-whatever@website.com:/home /location/of/local/folder
if [ $? != "0" ]
then
echo "There was a problem"
else
tar zcf /var/backups/home-`date +%Y%m%d`.tar.gz /location/of/local/folder
fi
This is a brilliant and insightful answer. Thank you very much for taking the time. :) You've really helped me. Thank you.
– Thomas Clayson
May 8 '12 at 8:14
add a comment |
Commands in a shell script are executed sequentially. If your first command is rsync, the next command will not execute until rsync completes.
What you want to be sure of is that rsync finishes successfully before continuing to the next command.
This is not the most elegant solution, but the easiest to implement.
rsync -e ssh -az user-whatever@website.com:/home /location/of/local/folder &&
tar zcf /var/backups/home-`date +%Y%m%d`.tar.gz /location/of/local/folder
Keep in mind this will only work if the exit status of rsync is 0. Any other exit status and command 2 will not run.
AND and OR lists are sequences of one of more pipelines separated by the &&
and || control operators, respectively. AND and OR lists are executed
with left associativity. An AND list has the form
command1 && command2
command2 is executed if, and only if, command1 returns an exit status of zero.
You could add more intelligence to your script if you performed different actions based on the rsync EXIT VALUES.
#!/bin/bash
PATH=/bin:/usr/bin:/sbin:/usr/sbin
rsync -e ssh -az user-whatever@website.com:/home /location/of/local/folder
if [ $? != "0" ]
then
echo "There was a problem"
else
tar zcf /var/backups/home-`date +%Y%m%d`.tar.gz /location/of/local/folder
fi
This is a brilliant and insightful answer. Thank you very much for taking the time. :) You've really helped me. Thank you.
– Thomas Clayson
May 8 '12 at 8:14
add a comment |
Commands in a shell script are executed sequentially. If your first command is rsync, the next command will not execute until rsync completes.
What you want to be sure of is that rsync finishes successfully before continuing to the next command.
This is not the most elegant solution, but the easiest to implement.
rsync -e ssh -az user-whatever@website.com:/home /location/of/local/folder &&
tar zcf /var/backups/home-`date +%Y%m%d`.tar.gz /location/of/local/folder
Keep in mind this will only work if the exit status of rsync is 0. Any other exit status and command 2 will not run.
AND and OR lists are sequences of one of more pipelines separated by the &&
and || control operators, respectively. AND and OR lists are executed
with left associativity. An AND list has the form
command1 && command2
command2 is executed if, and only if, command1 returns an exit status of zero.
You could add more intelligence to your script if you performed different actions based on the rsync EXIT VALUES.
#!/bin/bash
PATH=/bin:/usr/bin:/sbin:/usr/sbin
rsync -e ssh -az user-whatever@website.com:/home /location/of/local/folder
if [ $? != "0" ]
then
echo "There was a problem"
else
tar zcf /var/backups/home-`date +%Y%m%d`.tar.gz /location/of/local/folder
fi
Commands in a shell script are executed sequentially. If your first command is rsync, the next command will not execute until rsync completes.
What you want to be sure of is that rsync finishes successfully before continuing to the next command.
This is not the most elegant solution, but the easiest to implement.
rsync -e ssh -az user-whatever@website.com:/home /location/of/local/folder &&
tar zcf /var/backups/home-`date +%Y%m%d`.tar.gz /location/of/local/folder
Keep in mind this will only work if the exit status of rsync is 0. Any other exit status and command 2 will not run.
AND and OR lists are sequences of one of more pipelines separated by the &&
and || control operators, respectively. AND and OR lists are executed
with left associativity. An AND list has the form
command1 && command2
command2 is executed if, and only if, command1 returns an exit status of zero.
You could add more intelligence to your script if you performed different actions based on the rsync EXIT VALUES.
#!/bin/bash
PATH=/bin:/usr/bin:/sbin:/usr/sbin
rsync -e ssh -az user-whatever@website.com:/home /location/of/local/folder
if [ $? != "0" ]
then
echo "There was a problem"
else
tar zcf /var/backups/home-`date +%Y%m%d`.tar.gz /location/of/local/folder
fi
edited May 4 '12 at 16:39
answered May 4 '12 at 16:12
George MGeorge M
9,37123347
9,37123347
This is a brilliant and insightful answer. Thank you very much for taking the time. :) You've really helped me. Thank you.
– Thomas Clayson
May 8 '12 at 8:14
add a comment |
This is a brilliant and insightful answer. Thank you very much for taking the time. :) You've really helped me. Thank you.
– Thomas Clayson
May 8 '12 at 8:14
This is a brilliant and insightful answer. Thank you very much for taking the time. :) You've really helped me. Thank you.
– Thomas Clayson
May 8 '12 at 8:14
This is a brilliant and insightful answer. Thank you very much for taking the time. :) You've really helped me. Thank you.
– Thomas Clayson
May 8 '12 at 8:14
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f37912%2ftrying-to-create-a-cron-to-rsync-then-tar-the-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