You are not logged in.

#1 2009-05-12 02:15:42

Lexion
Member
Registered: 2008-03-23
Posts: 510

Simple Config file backup script

It's quite simple, make a backup of all your important config files (I suppose it could be used for other types of files) to your home dir.
I'm always wrecking my system because of config file mishaps, so I wrote this.  It's called 'cb' for Config Backup.

cb:

#!/bin/bash

if [[ $1 == "-l" ]]
then
    for i in $(cat $HOME/.cbrc)
    do
        echo $i
    done
    exit
fi

if [[ $1 == "-h" ]]
then
    echo "cb (Config Backup) version 0.1a"
    echo "Usage: cb -[lhr]"
    echo "-l    Don't copy anything, just display the config file"
    echo "-h    Show this help/version"
        echo "-r   Restore files"
    echo "Written in 2009 by Lexion (as known on the Arch Linux forums)"
    echo "and licenced under the GPL"
    exit
fi

if [[ $1 == "-r" ]]
then
    echo "Putting configs in your home directory,"
    echo "you should find them there"
    cp $HOME/.cbbk/* $HOME
    exit
fi

if [ -a $HOME/.cbrc ]
then
    echo "Starting cb backup process..."
    echo "-----------------------------"
else
    touch $HOME/.cbrc
fi

if [ -d $HOME/.cbbk ]
then
    echo "Backing up my own config file..."
    cp $HOME/.cbrc $HOME/.cbbk/.cbrc
else
    mkdir -p $HOME/.cbbk
fi

for i in $(cat $HOME/.cbrc)
do
    echo "Backing up" $i"..."
    cp $i $HOME/.cbbk
done

echo "----------------"
echo "Done backing up."

It uses a config file called .cbrc (btw it creates it automatically).  Here is an example .cbrc file:

/etc/rc.conf
/home/me/.Xdefaults
/home/oliver/.xmonad/xmonad.hs
/etc/mkinitcpio.conf
/etc/rc.sysinit

The backup directory, .cbbk, is also created automatically.  I would recommend
you run cb in /etc/rc.local to backup your configs at boot.  It is run as follows:

# cb

I hope you enjoy it as much as I do.


urxvtc / wmii / zsh / configs / onebluecat.net
Arch will not hold your hand

Offline

#2 2009-05-17 09:54:05

phutte
Member
Registered: 2009-02-13
Posts: 14

Re: Simple Config file backup script

I know next to nothin about bashscripts. This script is very inspiring in my learningprocess. Hopefully I will find a way to include the directorystructure in my backupfolder. However that could be implemented. I know how to manage that in .php, but this is a new challenge for me.
Thanks for the lesson there mr/mrs. Lexion

../sun-sun-please-go-away-and-do-comeback-another.......

Offline

Board footer

Powered by FluxBB