What's a good way to supply a password for automating a backup?

Solution 1:

  1. Don't roll your own backup solution.
    Seriously. Don't. You'll mess it up. There are plenty of great backup systems for Unix, and plenty of free ones, and plenty that are both.
    -Bacula (Free and good)
    -TarSnap (cheap and good)

  2. If you HAVE to do this, do it with passwordless SSH keys, and use forced commands to secure the target accounts. See the SSH man pages (ssh ; sshd - specifically re: authorized_keys) for more details.
    Implementation of the script (tar locally, rsync, etc.) would depend on your environment and needs -- do what makes sense.

Solution 2:

What part of the backup do you think requires a password? If you're talking about shipping the tarball to another server via ssh, then you should look at making an RSA key pair. It will allow a secure passwordless connection from one machine to another. You shouldn't be storing passwords in plaintext in any script.