-2

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?

nils50122
  • 21
  • 1
  • 7

2 Answers2

0

Yes,

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.

matiit
  • 103
  • 4
  • 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
0

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

/usr/bin/local/backup.sh

If you are happy add it as a cron job

Federico Galli
  • 918
  • 6
  • 16