1

I just wrote this script for backing up everything into a tar.gz file. Does it look okay? How can I get the tar file to transfer itself over to another server after executing? FTP from itself? I'm going to put this script into a weekly cron.

#!/bin/bash

rm ~/backup.tar.gz #removes old backup
BACKUP_DIRS=$HOME #$HOME is builtin, it goes to /home/ and all child dirs
tar -cvzf backup.tar.gz $BACKUP_DIRS

# run tar -zxvf to extract backup.tar.gz

3 Answers 3

2

FTP is the devil. SCP with RSA keypairs is a good way to move the files securely from server to server. As for the script, it looks fine.

6
  • Thanks for the response! THe script works, so I figured. Just wanted to make sure. How hard is SCP? Is there a script for the transfer? Nov 26, 2011 at 0:43
  • man scp isn't that difficult to read, is it :)
    – MDMarra
    Nov 26, 2011 at 0:58
  • I am now. My question is, how do you handle the passwords between the two servers when sending the files? THanks. Nov 26, 2011 at 1:21
  • RSA keypairs are passwordless.
    – MDMarra
    Nov 26, 2011 at 1:35
  • On the sending server, create an ssh key pair using "ssh-keygen -t dsa". Don't set a passphrase to encrypt the private key (by default, id_dsa). Take the associated public key and put it on the receiving server, in the receiving user's authorized_keys file. If the private key doesn't have a passphrase, it will not prompt you in a script.
    – cjc
    Nov 26, 2011 at 1:37
6

If you don't have many files that are changing, you might use rsync instead of making a big tar ball. Rsync will only send changes, so it's much more network efficient than what you're proposing. Maybe start by looking at something like this:

http://lifehacker.com/196122/geek-to-live--mirror-files-across-systems-with-rsync?tag=softwarersync

3

Depending on the size of the server, you are creating an awful lot of duplicates. If I were you, I'd only back files that were modified. You should also datetime-stamp the file.

Here's what I would do.

  • Do full back 1x per month or per week
  • Incremental backups for all other days
  • datetime-stamp the file for easier recovery

A real easy way to check the modified date of the file would be:

date -r $file +%F

so basically you can wrap that in a function and if the function doesn't match the date of the last backup, add it to the archive/backup. Otherwise move on.

HTH

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .