1

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?

gratsby
  • 3,107
  • 4
  • 20
  • 20

4 Answers4

3

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.

kirelagin
  • 13,248
  • 2
  • 42
  • 57
  • +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. – gcbenison Jun 03 '13 at 02:15
3

You could do this with Rsync. It supports ssh tunneling and is a very good tool for backups.

ScotchAndSoda
  • 3,811
  • 4
  • 34
  • 38
1
zip -R backup.zip directory && scp backup.zip username@server:destination_path

should do the job. As stated above, you should definitely use key authentication for this.

iruvar
  • 22,736
  • 7
  • 53
  • 82
0

You can try to use "Twisted conch library"

Conch is an SSHv2 implementation written in Python.

There is an example here:

Community
  • 1
  • 1
Ali Okan Yüksel
  • 338
  • 1
  • 13