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?

4 Answers 4

3

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

Sign up to request clarification or add additional context in comments.

Comments

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.

1 Comment

+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.
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.

Comments

0

You can try to use "Twisted conch library"

Conch is an SSHv2 implementation written in Python.

There is an example here:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.