User Tools

Site Tools


linux:gentoo-backup

Gentoo System Backup

I just want to backup my Gentoo System, like a stage-X, so I can restore it when the system is broken, just with one command like

tar xvf gentoo-stage-x.tgz

So I found a script in the Gentoo forum

After some minor adjust, the script works as I want.

Actually, this script is really simple, the core command is:

cat ${list} | xargs tar zlcvf  ${BKPDIR}/${type}.`date +%Y-%m-%d-%H%M`.${ext}

Just use the tar to create the package according to the directory list in sys.lst

#!/bin/sh 
# for FULL backups 
# this backs up the important stuffs listed in ${lists} to ${BKPDIR} 
# the lists *should* be in ${BKPDIR} and named <whatever>.lst 
# the resulting backups will be <whatever>.<timestamp>.tgz 
# 
# notes: 
# variables in CAPS are ok for you to set 
# change the other variables if you know what you're doing 
# you can get fancy in the lists... (think xargs *wink*) 
# assumes /boot is usually unmounted, and has an /etc/fstab entry 
# follow your security policy when setting perms on ${BKPDIR} 
# 
# written by razamatan 
# 
# DISCLAIMER: razamatan didn't write this if something goes wrong 
 
BKPDIR=/home/pjq/backup            # where the backups go 
BOOT=boot #sys                        # list that has /boot 
NUMBKPS=3                       # how many backups to keep 
 
if [ ! -d ${BKPDIR} ] ; then 
        echo ${BKPDIR} is not a valid directory or is non-existant 
        exit -1
fi 
 
lists=${BKPDIR}/*.lst 
ext=tgz 
 
for list in `ls ${lists}`; do 
        type=`basename ${list} .lst` 
 
        if [ ${type} = ${BOOT} ] ; then mount /boot ; fi 
        echo cat ${list} | xargs tar zlcvf  ${BKPDIR}/${type}.`date +%Y-%m-%d-%H%M`.${ext} # > /dev/null 2>&1 
        cat ${list} | xargs tar zlcvf  ${BKPDIR}/${type}.`date +%Y-%m-%d-%H%M`.${ext} # > /dev/null 2>&1 
        if [ ${type} = ${BOOT} ] ; then umount /boot ; fi 
 
        num=${NUMBKPS} 
        for evict in `ls -t ${BKPDIR}/${type}.*.${ext}`; do 
                if [ ${num} -le 0 ] ; then rm -f ${evict} 
                else num=$((${num}-1)) ; fi 
        done 
done

/bin
/boot 
/root 
--exclude=/dev
/etc 
/sbin
/lib
--exclude=/sys
/lib32
/lib64
/usr
--exclude=/usr/portage/distfiles 
--exclude=/usr/src/linux
--exclude=/usr/portage
/usr/src/linux/.config 
/var

/var/www/dokuwiki/wiki/data/pages/linux/gentoo-backup.txt · Last modified: 2016/05/05 13:07 (external edit)