You are not logged in.

#1 2008-06-17 10:36:00

bsdson.tw
Member
From: Taiwan
Registered: 2005-05-06
Posts: 161

simple config backup script

Hello,

Below is a script to backup configuration files you want into a directory, and to collect installed package names, and sudo abilities.
It could be used for reference while setting up a new Arch system.

Hope it helps.

BR,
bsdson.tw

USAGE:
<script name> <destination directory> <file list, optional, default to "script name".conf>

PS. It depends on a tool "realpath", although you may remove the line invoking "realpath" in the script.

#!/bin/bash

echo init
conf="$0.conf"

echo check parameters
if [ 1 -eq $# ]; then
    echo good
elif [ 2 -eq $# ]; then
    conf="$2"
else
    # @todo: error handling
    echo plz check usage
    echo "$0 dest_dir file_list"
    echo @param dest_dir=destination directory
    echo "@param file_list=files to backup, default to $0.conf"

    exit 4
fi

mkdir -p "$1"
echo "backing up files listed in file=$conf into directory=$1"
cp "$conf" "$1/FILE_LIST.TXT"

# backup configs
while read line; do
    if [ -z "${line##\#*}" ]; then
        # skip empty lines and/or comments
        echo "$line"
    elif [ ! -e "$line" ]; then
        # @todo: error handling
        echo "file=$line does not exist!"
        exit 6

    else
        # give the file a new name
        bak_name=$(realpath "$line")
        #bak_name=${bak_name#/}
        bak_name=${bak_name//\//_}
        echo "$line => $bak_name"

        cp -a "$line" "$1/$bak_name"
    fi
done < "$conf"

echo collecting installed packages
pacman -Qti > "$1/PACMAN_QTI.OUT"

echo backup sudo abilities for me
sudo -l > "$1/SUDO_L.OUT"

echo leave a timestamp
date > "$1/DATE.OUT"

echo done

and below is the config file I am using.

# grub
/boot/grub/menu.lst
/etc/mkinitcpio.conf

# system init
/etc/inittab
/etc/rc.conf
/etc/X11/xorg.conf

# really essential
/etc/fstab
/etc/group
/etc/passwd

# essential 2
/etc/locale.gen
/etc/ld.so.conf
/etc/modprobe.conf

# pacman
/etc/pacman.conf

# network
/etc/exports
/etc/hosts
/etc/hosts.allow
/etc/hosts.deny
/etc/resolv.conf
/etc/conf.d/bridges

# others
/etc/sudoers
/etc/fonts/local.conf

# my own
/home/bsdson/.bashrc
/home/bsdson/.xsession
/home/bsdson/.xinitrc
/home/bsdson/.vimrc

Last edited by bsdson.tw (2008-06-17 10:39:43)

Offline

Board footer

Powered by FluxBB