# best way to backup a server?

## taskara

Hi,

I am wondering what's the best way for me to backup my server.

I am thinking of running an external usb2 / firewire drive and backing up the entire system to it.

but I really am not sure where to go.

I guess I could run a script to tarball everything, but is there a way to combat corruption? perhaps with md5sums?

it's a file, web, print, game server running gentoo..

any advice / opinions would be appreciated.

cheers

----------

## red0x

USB hard drive could be cool, but, why don't you try using rsync.  I think its mostly for network backups.  Also, you could try flexbackup.  Both of these are in portage if my memory serves me correctly.

----------

## taskara

thanks.. I'll check them out..

I guess there are things like "Amanda" now too.. perhaps it's workable these days..

cheers

----------

## ryandlugosz

 *red0x wrote:*   

> USB hard drive could be cool, but, why don't you try using rsync.  I think its mostly for network backups. 

 

Rsync backup is great & works well whether you're using a network or just another mounted drive.  FWIW - if you are using network, it can connect via ssh.

I've got a nice setup on my server right now using this; it's just a personalized version of the info that can be found here:

http://www.mikerubel.org/computers/rsync_snapshots/

----------

## taskara

ta, I'll check it out!

----------

## dhunt

Try mondo-rescue. You can make ISO's or what ever with it. Very easy to use/restore.

----------

## jhmartin

I've got a removable HD bay and 2 cartridges (just 2 regular 3.5in HD's in a 5.25 cardridge) and every week I put one in the Windows machine and do the following from my linux server:

```

#!/bin/bash

clear

mount /mnt/backup

ISMOUNTED=`mount|grep -c "/mnt/backup"`

if [ $ISMOUNTED -lt 1 ]; then

 echo "ERROR: Mount Failed /mnt/backup"

 exit 1

fi

mount /boot

ISMOUNTED=`mount|grep -c "/boot"`

if [ $ISMOUNTED -ne 1 ]; then

 echo "ERROR: Mount Failed /boot"

 exit 1

fi

#Perform mysql export

/usr/bin/mysqldump -A -a --opt --password=XXXXXX | gzip >/var/lib/mysql/alldatabases.dmp.gz

#estimate bytes for use by PipeViewer

TOTALKBYTES=`df / /usr/ /home /var/ /opt /boot |grep "^/" | awk '{sum += $3;} END {print sum;}'`

TOTALBYTES=$((TOTALKBYTES * 1024))

echo $TOTALBYTES

DIR=/mnt/backup/`hostname`/`date +%Y%m%d%H%M`

mkdir -p $DIR

if [ ! -d $DIR ]; then

 echo "Error: mkdir Failed"

 exit 1

fi

tar --force-local -PcpO  --exclude=/var/tmp/*  --exclude=/proc --exclude=/var/tmp/t --exclude=/mnt/backup / | pv -cW  -N tar -s $TOTALBYTES | gzip | pv -cW  -N gzip | gpg -c --compress-algo Uncompressed --passphrase-fd 3 3<backup.pass -q --batch | pv -cW  -N gpg | split -b 500m - $DIR/backup-

umount /mnt/backup

umount /boot

```

pv is a nifty utility called PipeViewer that gives you an a progress indicator on pipes. I also pipe through gpg since since I store the drives at work (for offsite backup).

----------

## taskara

thanks for all your suggestions guys - one more question

what about people's mail (using .maildir)?

if some deletes something accidentally from their mail, how easy is it to restore that mailbox / email with your suggestions above?

can I keep a week's worth of backup? ie a cycle of 5 backups each week?

cheers!

----------

## ryandlugosz

 *taskara wrote:*   

> 
> 
> if some deletes something accidentally from their mail, how easy is it to restore that mailbox / email with your suggestions above?
> 
> can I keep a week's worth of backup? ie a cycle of 5 backups each week?
> ...

 

This is exactly what my rsync back system does... I keep 15 days worth of "backups" with it.... After 15 days the oldest backup is deleted.  The nice part about this system is that it only requires the space of *one* full backup plus the size of the changes between each backup.  However, each backup directory appears to be a full snapshot of the system at the time the backup was made.  The magic is in the fact that you tell rsync to use hardlinks to "backup" the files that were unchanged from the previous backup.

-Ryan

----------

## taskara

 *ryandlugosz wrote:*   

>  *taskara wrote:*   
> 
> if some deletes something accidentally from their mail, how easy is it to restore that mailbox / email with your suggestions above?
> 
> can I keep a week's worth of backup? ie a cycle of 5 backups each week?
> ...

 

this sounds exactly what I want.. I thought as much  :Wink: 

thanks - I'm getting the new mail server up this weekend hopefully, and I'll keep u posted on how I got with rsync.

cheers

----------

## tam1138

The rsync method is a great solution for many problems.  But keep in mind that it doesn't guard against catastrophic failure of the machine running the rsync, nor does it guard against site-wide failures.  It is an administrative decision as to whether these are reasonable risks, and any person making such a decision ought to be fully cognizant thereof.  I'm not saying it doesn't fit your needs, but I am encouraging you to fully evaluate your needs and the risks posed by potential solutions.

----------

## taskara

 *tam1138 wrote:*   

> The rsync method is a great solution for many problems.  But keep in mind that it doesn't guard against catastrophic failure of the machine running the rsync, nor does it guard against site-wide failures.  It is an administrative decision as to whether these are reasonable risks, and any person making such a decision ought to be fully cognizant thereof.  I'm not saying it doesn't fit your needs, but I am encouraging you to fully evaluate your needs and the risks posed by potential solutions.

 

definately.. however if the building burned down I'm not sure much would help get email back up - short of tape backup offsite.

and if the building was burned down - they'd lose all their paper records, so who cares about emails  :Confused: 

mind you I COULD make it rsync to my linux server across the internet..

----------

## ryandlugosz

[quote="taskara"] *tam1138 wrote:*   

> 
> 
> mind you I COULD make it rsync to my linux server across the internet..

 

He's right, you need an offsite backup method.  I keep a copy of my most important items (cvs repo, documents, pics, etc) on a remote box.  This transfer is also an automated rsync.

The only issue I have with the rsync method is that it seems that you lose all permissions when you save the stuff remotely onto a box that doesn't have all of the same users setup that the source box does.  I guess this makes sense, but I wish it were easier to deal with... I'd love to be able to keep a system image remotely using this method.

... I kind of wonder if the permissions thing affects my normal backup - if I were to boot from a boot disc & then mount & switch into my backup dir the permissions would be pooched.  However, my theory is that I could boot, mount & then chroot into my backup snapshot & then everything should be correct.  I would then mount a new drive in this chroot & copy everything to it.  I'll have to test this thoery... better to know now than when I need it....  anyone have any thoughts on that?

----------

## sapphirecat

 *ryandlugosz wrote:*   

> ... I kind of wonder if the permissions thing affects my normal backup - if I were to boot from a boot disc & then mount & switch into my backup dir the permissions would be pooched.  However, my theory is that I could boot, mount & then chroot into my backup snapshot & then everything should be correct.  I would then mount a new drive in this chroot & copy everything to it.  I'll have to test this thoery... better to know now than when I need it....  anyone have any thoughts on that?

 

Permissions are stored as UID/GID numbers on disk, so there shouldn't be any damage done IF the UID/GIDs are preserved by the backup host. If your backup snapshot includes /etc/passwd and /etc/groups, then chroot'ing into it should make ls -l and friends work fine because those files would contain the correct ID-to-name mapping for the backed up files. If the CPU architectures don't match, it may be tricky or impossible to run the right ls, but for that sash would probably work.

Disclaimer: this is only to the best of my understanding, because I've never actually done such things.

----------

## tam1138

 *ryandlugosz wrote:*   

> He's right, you need an offsite backup method.  I keep a copy of my most important items (cvs repo, documents, pics, etc) on a remote box.  This transfer is also an automated rsync.

 

Whoa there, cowboy.  He doesn't necessarily NEED offsite backups; he needs to weigh the costs and benefits.  Some people, like you and me, view the inconvenience of offsite backups as a very reasonable price for the security it buys.  Others don't.  I would instead implore people considering backups to decide for themselves.  Of course, if they get stung, it will affect their future decisions.  :Wink: 

----------

## zeky

I say: rsync is AWESOME peace of tool. I use that to bacup all my servers. It works like a charm  :Smile: 

----------

## bigsmoke

 *ryandlugosz wrote:*   

> 
> 
> Rsync backup is great & works well whether you're using a network or just another mounted drive.  FWIW - if you are using network, it can connect via ssh.

 

Indeed. I use rsync to backup my Gentoo system to my external USB2 HD, which works perfectly fine.

I've written a little script (/sbin/backup.sh) that mounts the disk (after I manually power it up), runs the rsync commands and umounts it again.

Now, if only I'd run this script a little more often than once a month I might actually be safe   :Embarassed: 

----------

## trossachs

Can rsync be used to backup my system onto a tape drive? I've downloaded Amanda also as I've been told that it is good for tape stuff. But can anyone point out some URL that I can go to for some 'basic here's how to backup your system now' information?

I can do all the complicated stuff later, I just need to have at least one copy of my system. thx.

----------

