about summary refs log blame commit diff stats
path: root/core/scripts/backup-system.sh
blob: 379e449869137a16cbf2d7b19ee19934b5c4f671 (plain) (tree)
1
2
3
4
5
6
7
8







                                                  





























































                                                                                                                                                                                                                                 
#!/bin/sh

echo -n "root directory you want backup (/mnt/): "
read ROOT_DIR

echo -n "where you want to save (/home/user): "
read DEST_DIR

bk_coll() {
    col=$1
    # make copy of packages
    mkdir ${BKDIR}/${col}
    while read line; do
            if [ ! -f /usr/ports/packages/${line} ]; then
                echo "Building package: ${line};\n"
                name=$(echo ${line} | cut -d "#" -f 1)
                sudo prt-get update -fr ${name}
            fi

            if [ -f /usr/ports/packages/${line} ]; then
                echo "Backing up package: ${line}"
                echo ${line} >> ${BKDIR}/backup.pkg
                cp /usr/ports/packages/${line} ${BKDIR}/${col}/
            else
                echo "Package not found: ${line}"
                echo ${line} >> ${BKDIR}/${col}-notfound.pkg
            fi
    done < $BKDIR/${col}.pkg
}

# Temporary directory
BKDIR=$(pwd)/bkdir
mkdir -p ${BKDIR}

# must be using gwak instead of sed, xargs and echo
prt-get listinst -v | sed -s s/" "/#/g | xargs -i echo {}.pkg.tar.gz > ${BKDIR}/installed.pkg

# make list and copy installed core packages
prt-get printf "%i %p %n#%v-%r.pkg.tar.gz\n" | grep "yes /usr/ports/core" | cut -d " " -f 3 > ${BKDIR}/core.pkg
bk_coll "core"


prt-get printf "%i %p %n#%v-%r.pkg.tar.gz\n" | grep "yes /usr/ports/opt" | cut -d " " -f 3 > $BKDIR/opt.pkg
bk_coll "opt"

prt-get printf "%i %p %n#%v-%r.pkg.tar.gz\n" | grep "yes /usr/ports/contrib" | cut -d " " -f 3 > $BKDIR/contrib.pkg
bk_coll "contrib"

prt-get printf "%i %p %n#%v-%r.pkg.tar.gz\n" | grep "yes /usr/ports/xorg" | cut -d " " -f 3 > $BKDIR/xorg.pkg
bk_coll "xorg"

prt-get printf "%i %p %n#%v-%r.pkg.tar.gz\n" | grep -v "yes /usr/ports/core" | grep -v "yes /usr/ports/opt" | grep -v "yes /usr/ports/contrib" | grep -v "yes /usr/ports/xorg" | grep "yes " | cut -d " " -f 3 > $BKDIR/other.pkg

#echo $DES_DIR
#echo $ROOT_DIR
#
#tar --xattrs -zcpf $DEST_DIR/system-backup-`date '+%Y-%j-%H-%M-%S'`.tar.gz \
#    --directory=$ROOT_DIR \
#    --exclude=usr/ports \
#    --exclude=usr/src \
#    --exclude=var/run \
#    --exclude=var/lock \
#    --exclude=srv \
#    --exclude=mnt \
#    --exclude=home \
#    --exclude=dev \
#    --exclude=run \
#    --exclude=tmp \
#    --exclude=proc \
#    --exclude=sys .