Do you expect to have one tar file per backup?
What you might do is have a script which creates a tar backup file with the day name in the filename, then copy that across to the remote machine, overwriting an old file if necessary.
tar can compress archives as it makes them, no need for a separate step for this. You should configure ssh to use public key authentication to allow remote login without password for the backup user. You can then use scp from a script to do the file transfer.
Something like this:
Code:
#!/bin/bash
cd /path/to/files/to/backup
backup_file="backup_$(date +%a).tar.gz"
tar zcf "$backup_file" * &&
scp "$backup_file" remoteuser@remotehost:/path/to/backups &&
rm * &&
echo "all was OK" ||
echo "error making $backup_file" |mailx -s "backup error" backupadmin@host.com
For this sort of thing to work, you have some setup to do:
- mail delivery must be working
- mailx must be installed
- ssh public key auth must be set up (for scp)
- the rm command must be correct!