I want to create the cron-job for the following steps:

  1. Backup my entire ubuntu server with the following command:

tar -cvpzf backup.tar.gz --exclude=/backup.tar.gz --exclude=/proc --exclude=/tmp --exclude=/mnt --exclude=/dev --exclude=/sys /

  1. after the backup in the archive is finished i want to rsync the archive with the following command:

sudo rsync -avz /backup.tar.gz -e "ssh -i /path/.ssh/ssh-key -p Port" backup@xxx.xxx:/path/path/path

Can we set a cron-job for this?


Why not? Create a batch script with the commands you know are working

echo "#!/bin/bash" >> /usr/bin/local/backup.sh
echo "tar -cvpzf backup.tar.gz --exclude=/backup.tar.gz --exclude=/proc --exclude=/tmp --exclude=/mnt --exclude=/dev --exclude=/sys /" >> /usr/bin/local/backup.sh
echo "sudo rsync -avz /backup.tar.gz -e "ssh -i /path/.ssh/ssh-key -p Port" backup@xxx.xxx:/path/path/path" >> /usr/bin/local/backup.sh
chmod +x /usr/bin/local/backup.sh

Then test it


If you are happy add it as a cron job



you can, for example, write a bash script which you then will set up in crontab to be run every X hours, minutes, days or weeks etc.

  • You read my post complete? I know how to set a cronjob daily, weekly or other. But i ask for set it to wait for the first job. – nils50122 Jul 28 '17 at 10:26
  • 1
    you write a script that runs one command then the next. There is not "wait until after" for cron commands. – Daniel Widrick Jul 28 '17 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.