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.


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/ \
  user@\!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.

  • 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. – NobbZ Dec 15 '11 at 8:14
  • 1
    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; would be your IP. – Caesium Dec 15 '11 at 9:31
  • 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 @ – Aaron D. Marasco Dec 16 '11 at 2:11
  • The key file that -i specifies is the private key file... starts with -----BEGIN DSA PRIVATE KEY----- – Aaron D. Marasco Dec 16 '11 at 2:13

Are you able to start a daemon and keep it running? You could run rsync in daemon mode if so.

Then on the client you would connect with an rsync:// url. For authorisation you could limit it to just your IP, I don't think there's an equivalent of SSH keys for it.

You need an rsyncd.conf, which can be anywhere, with something like:

    path = /path/you/want/to/sync
    read only = true
    hosts allow =

Then start the daemon..

rsync --daemon --config=rsyncd.conf

And then you can try to sync from it:

rsync -av rsync://server.ip/backup /local/backup/dir
  • I cant run any additional demons, also I have a dynamic IP, so authorizing against it is not possible :( – NobbZ Dec 15 '11 at 8:10

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.