Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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 cant create the necessary ~/.ssh/ directory and its contents for login via keys.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

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@192.168.1.99:/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|improve this answer
    
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; 192.168.1.99 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 @192.168.1.99. –  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:

[backup]
    path = /path/you/want/to/sync
    read only = true
    hosts allow = 1.2.3.4

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
share|improve this answer
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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