humpty promotes - Linux - Lubuntu Tips

Lubuntu linux Tips ZipRoot
zip your OS to a file for backup


You should first read about How to Clone your root partition to a backup stick.
This script will compress a mounted backup stick to a .tgz (tar.gz) file.

There will be a time when you've run out of backup usb sticks. And you might want to archive the backups.
This script merely compresses any attached backup disk to a .tgz file.

The compression script is ziproot.
The opposite (recovery) script is unziproot.

It is NOT advisable to zip the live system ('/'). Make sure you just archive the backup stick. In this example it is sdb1.

You will need another free partition to save the coompressed file. In this example it is sda4.

e.g ziproot sdb1 sda4
will zip /mnt/sdb1 to /mnt/sda4/rootbackup.tgz

ziproot
#!/bin/bash
#e.g ziproot sdb1 sda4 - zips /mnt/sdb1 to /mnt/sda4/rootbackup.tgz

if [[ "$1" == "" || "$2" == "" ]]; then
 echo please specify ziproot source dest; exit;
fi

if [ `whoami` != root ]; then
    echo Please run as root or sudo; exit
fi

echo zipping root on /mnt/$1 to /mnt/$2/rootbackup.tgz
echo enter to continue or ctrl-c to cancel
read

umount /dev/$2 2>/dev/null
mkdir /mnt/$2 2>/dev/null
mount /dev/$2 /mnt/$2
rm /mnt/$2/rootbackup.tgz >/dev/null

umount /dev/$1 2>/dev/null
mkdir /mnt/$1 2>/dev/null
mount /dev/$1 /mnt/$1
sync

tar -cvpzf /mnt/$2/rootbackup.tgz --one-file-system -C/mnt/$1/ ./
#-exclude=/mnt/
#--exclude-from=excludes.txt

echo output: /mnt/$2/rootbackup.tgz
echo done




e.g unziproot sdb1 sda4
will unzip /mnt/sda4 to /mnt/sdb1/rootbackup.tgz
The parameter ordering is the same but the action is in the opposite direction.
Make sure you unzip back to the same usb stick partition otherwise the stick will not boot, (and you might have to use prime-boot to re-prime it again).

unziproot
#!/bin/bash
#e.g unziproot sdb1 sda4 - unzips /mnt/sda4/rootbackup.tgz to /mnt/sdb1

echo unzipping /mnt/sda4/rootbackup.tgz to /mnt/$1

if [ "$1" == "" ]; then
 echo please specify destination e.g sdb1; exit;
fi
if [ `whoami` != root ]; then
    echo Please run as root or sudo; exit
fi

umount /dev/$1 2>/dev/null
mkdir /mnt/$1 2>/dev/null
mount /dev/$1 /mnt/$1
sync

tar -xvpzf /mnt/sda4/rootbackup.tgz -C /mnt/$1

echo output: /mnt/$1
echo done


It is up to you rename and organise your backup files. It's not something you have to do everyday so it should not be a problem.

More Lubuntu Tips




Leading Cloud Surveillance, Recording and Storage service; IP camera live viewing

Leading Enterprise Cloud IT Service; cloud file server, FTP Hosting, Online Storage, Backup and Sharing

Powered by FirstCloudIT.com, a division of DriveHQ, the leading Cloud IT and Cloud Surveillance Service provider since 2003.