Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

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.

share|improve this answer
    
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? –  user1062058 Nov 26 '11 at 0:43
    
man scp isn't that difficult to read, is it :) –  MDMarra Nov 26 '11 at 0:58
    
I am now. My question is, how do you handle the passwords between the two servers when sending the files? THanks. –  user1062058 Nov 26 '11 at 1:21
    
RSA keypairs are passwordless. –  MDMarra Nov 26 '11 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 '11 at 1:37
show 1 more comment

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

share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.