UNIX Backup & Recovery
TODO: mksysb, cpio, duplicity, deja-dup, cronopete
UNIX Backup for quick Restore
Backup for quick Restore retaining directory structure
The key to the quick restore is to backup files under the same mount point so that mv commands are almost instantaneous.
This script caters for a scenario where the directory you need to backup is itself a mount point by backing up to a subdirectory that is explicitly excluded from the backup set....
Backup
mkdir /toplevel/backupdir
find /toplevel/ -maxdepth 1 -not -path "/toplevel/backupdir" -not -path "/toplevel/" -exec cp -Rav {} /toplevel/backupdir \;
Restore
This combination of commands basically swaps the existing structure for the backup structure (i.e. it allows you to backout the restore if necessary).
find /toplevel/ -maxdepth 1 -type d -not -path "/toplevel/backupdir" -not -path "/toplevel/" -exec mv -f {} {}_old \;
mv /toplevel/backupdir/* /toplevel/
Remember to clean up files/directories that are no longer required.
Monitor Progress
If you start this script off immediately after you kick off the backup then the value of y should be reasonably accurate and the script will report approximate percentage complete each minute...
y=$(du -s upgrade_copy1 | cut -f1)
while [ 1 ]
do
date
x=$(du -s upgrade_copy1 | cut -f1)
x=$((x*100))
z=$((x/y))
echo $z
sleep 60
done
Worked Example
Make a multi-level directory structure.
In this example we will create directories under /restore/temp...
cd /restore/temp
mkdir -p level1-1/level2-1/level3-1
mkdir -p level1-1/level2-1/level3-2
mkdir -p level1-1/level2-1/level3-3
mkdir -p level1-1/level2-1/level3-4
mkdir -p level1-1/level2-2/level3-1
mkdir -p level1-1/level2-2/level3-2
mkdir -p level1-1/level2-2/level3-3
mkdir -p level1-1/level2-2/level3-4
mkdir -p level1-1/level2-3/level3-1
mkdir -p level1-1/level2-3/level3-2
mkdir -p level1-1/level2-3/level3-3
mkdir -p level1-1/level2-3/level3-4
mkdir -p level1-1/level2-4/level3-1
mkdir -p level1-1/level2-4/level3-2
mkdir -p level1-1/level2-4/level3-3
mkdir -p level1-1/level2-4/level3-4
mkdir -p level1-2/level2-1/level3-1
mkdir -p level1-2/level2-1/level3-2
mkdir -p level1-2/level2-1/level3-3
mkdir -p level1-2/level2-1/level3-4
mkdir -p level1-2/level2-2/level3-1
mkdir -p level1-2/level2-2/level3-2
mkdir -p level1-2/level2-2/level3-3
mkdir -p level1-2/level2-2/level3-4
mkdir -p level1-2/level2-3/level3-1
mkdir -p level1-2/level2-3/level3-2
mkdir -p level1-2/level2-3/level3-3
mkdir -p level1-2/level2-3/level3-4
mkdir -p level1-2/level2-4/level3-1
mkdir -p level1-2/level2-4/level3-2
mkdir -p level1-2/level2-4/level3-3
mkdir -p level1-2/level2-4/level3-4
mkdir -p level1-3/level2-1/level3-1
mkdir -p level1-3/level2-1/level3-2
mkdir -p level1-3/level2-1/level3-3
mkdir -p level1-3/level2-1/level3-4
mkdir -p level1-3/level2-2/level3-1
mkdir -p level1-3/level2-2/level3-2
mkdir -p level1-3/level2-2/level3-3
mkdir -p level1-3/level2-2/level3-4
mkdir -p level1-3/level2-3/level3-1
mkdir -p level1-3/level2-3/level3-2
mkdir -p level1-3/level2-3/level3-3
mkdir -p level1-3/level2-3/level3-4
mkdir -p level1-3/level2-4/level3-1
mkdir -p level1-3/level2-4/level3-2
mkdir -p level1-3/level2-4/level3-3
mkdir -p level1-3/level2-4/level3-4
mkdir -p level1-4/level2-1/level3-1
mkdir -p level1-4/level2-1/level3-2
mkdir -p level1-4/level2-1/level3-3
mkdir -p level1-4/level2-1/level3-4
mkdir -p level1-4/level2-2/level3-1
mkdir -p level1-4/level2-2/level3-2
mkdir -p level1-4/level2-2/level3-3
mkdir -p level1-4/level2-2/level3-4
mkdir -p level1-4/level2-3/level3-1
mkdir -p level1-4/level2-3/level3-2
mkdir -p level1-4/level2-3/level3-3
mkdir -p level1-4/level2-3/level3-4
mkdir -p level1-4/level2-4/level3-1
mkdir -p level1-4/level2-4/level3-2
mkdir -p level1-4/level2-4/level3-3
mkdir -p level1-4/level2-4/level3-4
Backup...
find /restore/temp/ -maxdepth 1 -not -path "/restore/temp/backupdir" -not -path "/restore/temp/" -exec cp -Rav {} /restore/temp/backupdir \;
Restore...
find /restore/temp/ -maxdepth 1 -type d -not -path "/restore/temp/backupdir" -not -path "/restore/temp/" -exec mv -f {} {}_old \;
mv /restore/temp/backupdir/* /restore/temp/