Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

backup Bash script

2 views
Skip to first unread message

Roger

unread,
Jan 5, 2001, 8:25:23 PM1/5/01
to
here's a small bash script that performs a backup of only the config files
(or other folders/files) that you want. i wrote it because i only have a
need to only back up certain files repetiously rather than use a tape
device (which is dog slow) to backup 200mb - 2 gigs of data.....i'd rather
just buy an entire seperate hdd to clone it to! there is a another bash
script very well written but is mainly for tape drives <bummer>

what would be nice is a seperate newsgroup for bash, but the only one i've
come across is gnu.bash.bugs and some other programming groups. since i
use mandrake constantly, decided, 'why not give back to the mandrake
community eh???'

directions are the usual, copy/edit/save it to file with an editor. chmod
+x filename to make it executable.

here it is:
--------------begin of file------------------------

#!/bin/bash
###############################################################################
# BACKUP USING BASH written in bash! <obvious to most!>
#
# Composed by Roger
#
# ro...@linuxfreemail-dontspam-me-andiwontspamyou.com
# remove the "-dontspam-me-andiwontspamyou" to reply
#
# Last edited on 12/30/2000
#
# Governed by the GNU Licensing...or whatever.
#
# - If you find any bugs or have written any improvements, let me know!
# I might incorporate them into this!
# - I accept compliments graciously but send all comments else where.
# Preferably, send them to a black hole!
#
# Description of Backup Bash Script:
# To do only an incremental backup of config files and other necessary files
# using
# a bash script. Maybe could also be automated by directly linking
# in as a daily/weekly/monthly cron job! This script was only intended to
make
# minimal sized backups since there are other harddrive utilities that will
# backup entire partitions with greater ease and conservation of space,
# including tape backup options.
#
# Some things that would be nice:
# 1) To have a seperate file list that will list the files or directories to
# backup. This may also easily create one archive instead of multiple
# archives(?). Although I like being able to decompress the *.tar.gz
files
# that I want to preveiw and backup. (One file can get quite large!)
#
# Why the username added to the archive filename?
#
# Obvious. A host computer may have more than one user using the backup
script.
# Adding the username to the filename enhances readability including the
# following 'Why the date?' reason!
#
# Why the date added to the archive filename?
#
# Because I don't trust computers. If by chance, I copy my archive to
another
# HDD or other media, the computer may redo the dates (as in MS Windows
case).
#
# Why not a recovery routine?
#
# I do not plan to have a restore option since 'ark' is nice and neat.
# With the gui of 'ark', one can easily preveiw their text files w/o
untar'ing!
# To unzip and untar with 'ark' is easily done, but to zip/tar on routine
# backups is a hinder with ark.
#
###############################################################################
clear
#
# Initialize Variables (0=no, 1=yes, ...)
#
set_archive_username=1
set_archive_date=0
backup_destination=/mnt/ext2_hdb2/backup
#
#check to see if $set_archive_username is set?
#
{
if [ $set_archive_username = "1" ]; then
archive_username="-"$(whoami)
echo 'ok set archive_username=system who'
echo $archive_username
else
archive_username=''
echo 'ok set archive_username=null'
fi
}
#
#check to see if $set_archive_date is set?
#
{
if [ $set_archive_date = "1" ]; then
archive_date="-"$(date '+%m''%d''%Y''-%H''%M')
echo 'ok set archive_date=system date'
echo $archive_date
else
archive_date=''
echo 'ok set archive_date=null'
fi
}
#
# Main
#
echo
echo
echo "Backup Being Made As Defined in: "$(pwd)$0
echo
echo 'Backup Destination: '$backup_destination
echo
echo "Backup Username set to: "$archive_username
echo
echo "Date of this backup: "$(date)
echo
echo
#
# exit # debugger exit!
#
# Following lines are in the format stated here!
# tar -czf [create,zip,f] [name of file to create] [file or folder to
backup]
#
tar -cpzf
"$backup_destination/backup"$archive_username"_backup"$archive_date".tar.gz"
~/backup
tar -cpzf
"$backup_destination/backup"$archive_username"_licq"$archive_date".tar.gz"
~/.licq
tar -cpzf
"$backup_destination/backup"$archive_username"_netscape"$archive_date".tar.gz"
~/.netscape/bookmarks.html ~/.netscape/custom.dic
tar -cpzf
"$backup_destination/backup"$archive_username"_kmail"$archive_date".tar.gz"
~/Mail
tar -cpzf
"$backup_destination/backup"$archive_username"_rc"$archive_date".tar.gz"
~/.gvimrc ~/.vimrc ~/.bashrc ~/.Xdefaults
tar -cpzf
"$backup_destination/backup"$archive_username"_system-config"$archive_date".tar.gz"
/etc/smb.conf /etc/wine.conf
echo ''
echo 'All Done!'
echo ''


--------------end of file--------------------------
--
Created with Linux Mandrake 7.2!
www.linux-mandrake.com
(remove 'nospamfilter-' in email to reply!)

Faux_Pseudo

unread,
Jan 6, 2001, 2:45:35 AM1/6/01
to
--(Once apon a time, in alt.os.linux.mandrake,)--
--(Roger said it like only they can.)--

>here's a small bash script that performs a backup of only the config files
>(or other folders/files) that you want. i wrote it because i only have a
>need to only back up certain files repetiously rather than use a tape
>device (which is dog slow) to backup 200mb - 2 gigs of data.....i'd rather
>just buy an entire seperate hdd to clone it to! there is a another bash
>script very well written but is mainly for tape drives <bummer>
>
>what would be nice is a seperate newsgroup for bash, but the only one i've
>come across is gnu.bash.bugs and some other programming groups. since i
>use mandrake constantly, decided, 'why not give back to the mandrake
>community eh???'

try comp.unix.shell


and i just recently rewrote my backup script

here here we go.

>--------------begin of file------------------------
#!/bin/bash
#/home/faux/shell/BAckUP mounts a partition
#called /BACkUP so that incase i do something like rm -fr /
#that data will still be safe
#see the second script in this post for it
#the partition is unmounted by cron latter
#for some reason if i try to unmount the partition
#inside the scirpt it gives a error and lots of bad things
#can happen
#
#
#these scripts runs once a day in cron
#
USAGE=" -r for restoring eth root and faux files
-s make a backup of almost ALL eth related files
-u make backups of /root/ and /home/faux"
while getopts sru o
do case $o
in r) /home/faux/shell/BACKUP
cd /
tar xzlf /BACKUP/FauxBackup.tgz
tar xzlf /BACKUP/BackupOfRoot.tgz
tar xzlf /BACKUP/eth.tgz
;;


s) /home/faux/shell/BACKUP
cd /
tar zcp $(find /etc/sysconfig/network-scripts/ -print) \
/etc/hosts /etc/HOSTNAME /etc/sysconfig/network /etc/networks \
/etc/rc.d/rc.inet1 /etc/rc.d/rc.inet2 /etc/sysconfig/network \
/etc/resolv.conf /etc/sysconfig/static-routes /sbin/ifup \
/sbin/ifdown /sbin/ifconfig /sbin/ifport /sbin/ifuser \
> /BACKUP/eth.tgz
;;

u) /home/faux/shell/BACKUP
#clean up the old backups
rm -f /BACKUP/bck[a-z]* /BACKUP/UID0* /BACKUP/faux*
#mv the old backups to a backup of a backup status
mv /BACKUP/Back* /BACKUP/bckroot.tgz
mv /BACKUP/Faux* /BACKUP/bckfaux.tgz
#remove the unnessacary
rm -f /root/.*~ ~/.*back* ~/.*bck* ~/.poplog ~/[.]*debug*
#save some of the important stuff
ls /usr/local/bin/ > /root/localbin
crontab -l > /root/croninfo

# make the backups
cd /BACKUP
tar zpc $(find /root/ -print | grep -v decode ) \
> BackupOfRoot.tgz
#make the backup into floppy/email sized bits
split --bytes=1m /BACKUP/Backu*
for i in `ls --color=never x[a-z][a-z]`
do mv `echo $i` UID0.$i
done
tar zpc $(find /home/faux/ -print | grep -v decode ) \
> FauxBackup.tgz
#make the backup into floppy/email sized bits
for i in `ls --color=never x[a-z][a-z]`
do mv `echo $i` /BACKUP/faux.$i
done
#remove the tmp files
rm -f /root/croninfo /root/localbin
cp /home/faux/shell/bck.sh /BACKUP/bck.sh
echo back of root and faux done

;;
*) echo "$USAGE" ;;
esac
done

>--------------end of file--------------------------

>--------------begin of file------------------------
#!/bin/bash
#you may wonder why i rewrite fstab to do this script
#the reason is i dont want /BACKUP mounted on system startup
if [ $(grep -cs BACKUP /etc/mtab) == 0 ] ; then
echo '/dev/hda5 /BACKUP ext2 defaults 1 1' >> /etc/fstab
mount /dev/hda5
echo mounted
else umount /dev/hda5
BACKUPLESS="$(grep -v hda5 /etc/fstab)"
echo "$BACKUPLESS" > /etc/fstab
echo unmounted
fi
>--------------end of file--------------------------

--
--(UIN=66618055)--
--(tt...@faux.local_04:45_/home/faux)-- cat .sig
GUI's are for slackers. ibpconf.sh 5 on freshmeat.net
The easiest way to customize the command line. By Faux_Pseudo


Roger

unread,
Jan 6, 2001, 6:58:00 PM1/6/01
to
Faux_Pseudo wrote:

lol...nice intro....nice to finally hear something on this...been searching
for a while.

0 new messages