I'm trying to create a script to automatically log me in to a password protected server to upload a file from an ubuntu directory automatically. I am doing this for the purposes of automatically backing up a directory every hour. I already know had to add cron jobs to run my script every hour, but I don't know how to SSH, zip my directory then upload it. I don't know bash scripting very well, and in fact I was thinking it might be easier for me to use a python script. What is the best way to go about doing this?
4 Answers
You could do this with Rsync. It supports ssh tunneling and is a very good tool for backups.
Comments
You absolutely need public keys instead of passwords. And using bash will be far easier than python. Simply zip your file and then scp it or rsync the whole dir.
1 Comment
gcbenison
+1 to that. And if you're going to protect your ssh keys with passphrases (usually a good idea), you'll need to learn a bit about ssh agents to avoid having to enter a passphrase every hour. The man page for ssh-agent is a good place to start.
You can try to use "Twisted conch library"
Conch is an SSHv2 implementation written in Python.
- http://twistedmatrix.com/documents/current/conch/
- http://twistedmatrix.com/documents/current/conch/examples/
There is an example here: