Using rsync in a cronjob when a password is needed

5,817

This is the command I use to backup to another machine:

rsync -av -e "ssh -i /root/ssh-rsync-valhalla-key" \
  --exclude lost+found \
  --delete-before \
  /mnt/backup/ \
  [email protected]:/cygdrive/r/\!Backups/Niflheim &

So you can use the -i to pass a keyfile to ssh. Of course, in your example, that means the keyfile itself will be sharable via HTTP if anybody ever figures out the filename.

Share:
5,817

Related videos on Youtube

NobbZ
Author by

NobbZ

There is not much to say... I am just me :)

Updated on September 18, 2022

Comments

  • NobbZ
    NobbZ 4 months

    Basically I have a bash script that fetches data from my server to perform a backup.

    As it is now I have to start that script manually, enter the password, and then wait for it to finish.

    I would like to set up a cronjob that handles the backup.

    But I really don't know how to handle the password in a cronjob.

    Also I can't use keys for this, because my provider does not provide the mechanisms I need to configure them.

    I have SSH access to my home folder, but in my home folder I don't have write access except for the http(s)docs directory. So I can't create the necessary ~/.ssh/ directory and its contents for login via keys.

  • NobbZ
    NobbZ about 11 years
    So the path in the ssh command would be the path to the keyfiles on the remote? Since I dont use https on the server and it is deactivated I could then throw my keyfiles into httpsdocs and they would be safe there. I will give that a try in the evening.
  • Caesium
    Caesium about 11 years
    No, the -i path is a local path. So he means run this in reverse; initiate the rsync from your server back to your home PC; 192.168.1.99 would be your IP.
  • Aaron D. Marasco
    Aaron D. Marasco about 11 years
    What @Caesium said - this command pushes. You need to have sshd running on your home machine (along with firewall port forwarding, etc, etc). In my example, it pushes everything in /mnt/backup/ to R:\!Backups\Niflheim on a Windows/Cygwin box @192.168.1.99.
  • Aaron D. Marasco
    Aaron D. Marasco about 11 years
    The key file that -i specifies is the private key file... starts with -----BEGIN DSA PRIVATE KEY-----