Difference between revisions of "Conventional Linux System Backup Methods"

From Free Knowledge Base- The DUCK Project: information for everyone
Jump to: navigation, search
(New page: conventional backup - a discussion with examples of various means to create backup archives of your linux system. archive files, folders, partitions, and your entire system with conventio...)
 
 
Line 242: Line 242:
 
*Mondo Rescue
 
*Mondo Rescue
  
 
+
== some related pages ==
 +
* [[Conventional Linux System Backup Methods]]
 +
* [[Disk Imaging for Linux]]
 +
* [[Disk Archiving Linux Commands]]
  
  
 
[[Category:Computer_Technology]]
 
[[Category:Computer_Technology]]
 
[[Category:Linux]]
 
[[Category:Linux]]

Latest revision as of 13:34, 30 October 2019

conventional backup - a discussion with examples of various means to create backup archives of your linux system. archive files, folders, partitions, and your entire system with conventional linux programs. December 11, 2004


Creating a backup of your Linux system without using commercial software or special backup utilities may be accomplished successfully with minimal technical complexity. Some of the programs used for creating backup archives discussed here include dd, dump, cpio, afio, tar and now pax.

"Backup plans need to be simple to implement or they will not get done - especially at home." -JC Pollman and Bill Mote

Back up your Master Boot Record

Backing up your MBR is highly recommended. Use a rescue disk to boot and with a blank floppy disk in drive issue the command:

 dd if=/dev/hda of=MBR bs=512 count=1

Later on you may restore your MBR if it gets corrupted by issue of:

 dd if=/mnt/MBR of=/dev/hda bs=446 count=1

Manual backup by copying to a backup drive

Harddrives are inexpensive. "tape drives are usually too expensive for the home network, and floppies are impractical. [...] the best compromise is using a spare hard drive." -JC Pollman and Bill Mote

The following examples copy directories and files.

a) use dd to copy / on /dev/hda1 to a /dev/hdb1 ( backup disk )

  dd if=/dev/hda1 of=/dev/hdb1 bs=1024k 

b) use tar to copy /home on /hda/dev5 to /dev/hdb5 ( backup disk )

  mount /dev/hdb5 /mnt/backup
  ( tar cf - /home ) | ( cd /mnt/backup ; tar xvfp - )
  umount /mnt/backup

c) use tar to backup /home to (backup disk)

  mount /dev/hdb5 /mnt/backup
  tar zcvf /mnt/backup/home.Date.tgz /home > /mnt/backup/home.Date.log
  umount /mnt/backup

d) copy /home on /dev/hda5 to a /dev/hdb5 ( backup disk ) with scp

  mount /dev/hdb5 /mnt/backup
  scp -par /home /mnt/backup
  umount /mnt/backup 
  scp -pr user1@host:/Source_to_Backup user2@BackupServer:/Backup_Dir 

e) using cpio to copy /home on /dev/hda5 to a /dev/hdb5 ( backup disk )

  mount /dev/hdb5 /mnt/backup
  find /home -print | cpio -pm /mnt/backup
  umount /mnt/backup 

f) using cpio to view the contents of the backup archive

  cpio -it < file.cpio

g) using cpio to extract a file from the archive

  cpio -id "usr/share/file/doc/*" < file.cpio

h) incremental backup example using tar

  LastBackupTime = `cat /Backup_Dir/Last.txt`
  tar zcvf --newer $LastBackupTime /Backup_Dir/Date.x.tgz $DIRS
  echo "Date" > /Backup_Dir/Last.txt

i) incremental backup example using find with tar

  Cnt = `cat /Backup_Dir/Last.txt`
  find $DIRS -mtime -$Cnt -print | tar zcvf /Backup_Dir/Date.$Cnt.tgz -T -
  echo "$Cnt +1" > /Backup_Dir/Last.txt

j) using find with cpio

   find /home -xdev | cpio -pm /mnt/backup

Manual backup by copying to a backup drive

Rsync is a well known command line utility used in synchronizing files between two computers, but rsync can also be used as an effective backup tool.

a) Using rsync to back up the system to a remote system

  rsync -e ssh -av raffi@BackupServer.your_domain.com::/home/Backup/xfer/*
  /destination/xfer
  rsync -avz --delete HomeServer::/home/* /Backup/destination

Debian / Knoppix system config + OS backup

This is not a system for backing up your user data. This is more specifically a way to restore your debian linux operating system to the same configuration with the same packages, software, and utilities install as before the system crashed. However, only software installed as debian packages are restored. What you downloaded in source, compiled yourself, and installed might just as well be considered user data for this example.

a) backup a complete package configuration to the floppy

  mount /dev/fd0
  dpkg --get-selections * > /mnt/floppy/pkg.lst

b) include your etc contained system configuration files

  tar zcvf /mnt/floppy/etc.tgz /etc
  umount /dev/fd0

This floppy disk contains a complete list of .deb packages that make up your system as well as the configuration files and scripts from /etc. Now you wish to restore this to the system.

a) do a bare minimum install of debain from the cdrom or whatever source

b) package manager for Debian to install

  dpkg --set-selections < /mnt/floppy/pkg.lst 

c) now your important configuration files

  cd / ; tar zdvf /mnt/floppy/etc.tgz

d) bring packages up to date installed

  apt-get update
  apt-get dist-upgrade  
     ( or apt-get dselect-upgrade ) ( or aptitude install ) 

Backup Script by Daniel O'Callaghan, modified by JC Pollman and Bill Mote

#!/bin/sh
# full and incr backup script
# created 27 Sep 99
# Based on a script by Daniel O'Callaghan <danny@freebsd.org>

#Change the 5 variables below to fit your computer/backup

COMPUTER=myserver                 # name of this computer
DIRECTORIES="/etc /home"                # directoris to backup
BACKUPDIR=/backup/backups         # where to store the backups
TIMEDIR=/backup/backups/last-full # where to store time of full backup
TAR=/bin/tar			  # name and locaction of tar

#You should not have to change anything below here 

PATH=/usr/local/bin:/usr/bin:/bin
DOW=`date +%a`              # Day of the week e.g. Mon
DOM=`date +%d`              # Date of the Month e.g. 27
DM=`date +%d%b`             # Date and Month e.g. 27Sep

# On the 1st of the month a permanet full backup is made
# Every Sunday a full backup is made - overwriting last Sundays backup
# The rest of the time an incremental backup is made. Each incremental
# backup overwrites last weeks incremental backup of the same name.
#
# if NEWER = "", then tar backs up all files in the directories
# otherwise it backs up files newer than the NEWER date. NEWER
# gets it date from the file written every Sunday.

               
if [ $DOM = "01" ]; then  # monthly full backup
	NEWER=""
	$TAR $NEWER -z -c -f $BACKUPDIR/$COMPUTER-$DM.tgz $DIRECTORIES
fi

if [ $DOW = "Sun" ]; then # weekly full backup
        NEWER=""
	NOW=`date +%d-%b`  
	echo $NOW > $TIMEDIR/$COMPUTER-full-date #update full backup date 
	$TAR $NEWER -z -c -f $BACKUPDIR/$COMPUTER-$DOW.tgz $DIRECTORIES

else    #make incremental backup - overwrite last weeks
	NEWER="--newer `cat $TIMEDIR/$COMPUTER-full-date`" #get date of last full backup
	$TAR $NEWER -z -c -f $BACKUPDIR/$COMPUTER-$DOW.tgz $DIRECTORIES
fi

Using pax for multi-volume archives

PAX (Portable Archive Interchange) is a multipurpose archiving utility and directory copying tool not available by default with some Linux distributions.

To back up a directory called 'images' type:

 pax -wvzf images.pax images/

switches used:

-w to write
-f name of pax archive
-v verbose output
-z compress

view the contexts without extraction

 pax -zf images.pax

Compression is optional. Unfortunately, pax prompts for interactive filenaming when the next volume is ready.

 pax -wvz -f archive.pax -B 1048576 pictures/

The first volume, archive.pax, is created and then the user is prompted for a name to assign the next volume, again and again until done.

Using star for multi-volume archives

star is an improved tar archiver with true incremental dump and restore features.

 star -c 
 star -c -f qwe tsize=1500k
 
                  

References for this document:

  • Backup for the Home Network
http://www.linuxgazette.com/issue47/pollman.html
  • Backing up your Linux desktop with rsync
http://applications.linux.com/applications/04/09/15/1931240.shtml?tid=13
  • Using pax FreeBSD
http://www.onlamp.com/pub/a/bsd/2002/08/22/FreeBSD_Basics.html
  • Star
http://cdrecord.berlios.de/old/private/star.html

Backup Utilities to Investigate:

  • Backup Utility
http://backuper.infrax.si/
  • back2cd
http://www.samag.com/documents/s=7033/sam0204c/sam0204c.htm
  • Mondo Rescue

some related pages