Archive for category Systems
CIFS it is…
This is the final, fully tested and functional remote backup script for linux… Finally 🙂
#!/bin/bash
# A straght forward system backup script
#
LOGBASE=/var/log/backup/log
BACKUP_ROOT_DIR=”a/facts77 a/can”                      ## Backup dirs; do not prefix /
NOW=$(date +”%a”)Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ## Get todays day
TSTAMP=$(date +”%l:%M:%S”)Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ## Get time stamp H:M:S
TDATE=$(date -I)Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ## Get todays date
TAPE=”/oracle55vm_backup”                              ## Backup device name
TAR_ARGS=””                                            ## Exclude file
EXCLUDE_CONF=/root/.backup.exclude.conf                ## Named file for file exclusion
LOGFILE=$LOGBASE/$TDATE.backup.log                     ## Backup Log file
FILELIST=$LOGBASE/$TDATE.backup.file-listing.log       ## Backup Log file list
UNAME=”xxx”
PWORD=”xxxXXXX”
SYSTEM=”`uname -n|cut -c 1-10`”
# Path to binaries
TAR=/bin/tar
MKDIR=/bin/mkdir
#
full_backup(){
local old=$(pwd)i
cd /
# Mount the samba destination
mount.cifs //bufvmfacts01/G/oracle55vm_backup $TAPE -o username=$UNAME,password=$PWORD
# Search the directory for files older than 7 days and delete them
find /oracle55vm_backup -type f -mtime +7|xargs -r rm -f
# Run the backup
tar -zcvf $TAPE/$SYSTEM.bak.`date -I`.tgz $BACKUP_ROOT_DIR # gzipping these
cd $old
}
# Make sure all dirs exits
verify_backup_dirs(){
local s=0
for d in $BACKUP_ROOT_DIR
do
if [ ! -d /$d ];
then
echo “Error : /$d directory does not exit!”
s=1
fi
done
# if not; just die
[ $s -eq 1 ] && exit 1
}
# Make some kind of status report
report_backup_info(){
touch $LOGBASE/$TDATE.backup.file-listing.log
cd $TAPE
echo ” ”
echo ”                       **** Backup Report ****”
echo ”                       ****  $TDATE ****”
echo ” ——————————————————————————— ”
echo ” ################################################################################# ”
echo ” _________________________________________________________________________________ ”
echo ” ”
echo ” ”
echo ” Backup start time: $TSTAMP”
echo ” Operating System: `cat /etc/redhat-release`”
echo ” ”
echo ” Size of the complete archive: `tar -ztvf $SYSTEM.bak.$TDATE.tgz|wc -c` Bytes”
echo ” Size of the logged archive:  `cat $FILELIST|wc -c` Bytes”
echo ” ”
echo ” File count of the completed archive: `tar -ztvf $SYSTEM.bak.$TDATE.tgz|wc -l` Files”
echo ” File count of the logged archive:   `cat $FILELIST|wc -l` Files”
echo ” ”
echo ” Remote CIFS Directory Listing:”
ls -lh
echo ” ”
echo ” Disk Summary:”
df -h
echo ” ”
echo ” _________________________________________________________________________________ ”
echo ”                                                                                  ”
echo ” ################################################################################# ”
echo ” ——————————————————————————— ”
echo ” ”
cd –
} > $LOGFILE 2>&1
#
#
# Clean Up
clean_up(){
cd /
umount $TAPE # unmount the cifs mount
# Email the report
mail -s “System Backup $SYSTEM” gconklin@proserve-solutions.com < $LOGFILE
}
#
#
#### MAIN ####
#
# Make sure log dir exits
[ ! -d $LOGBASE ] && $MKDIR -p $LOGBASE
#
# Verify dirs
verify_backup_dirs
#
#
# Okay let us start backup procedure
# If it is Monday-Friday make a full backup;
# Weekend no backups
full_backup > $FILELIST 2>&1
#
#
# Make the simple report
report_backup_info
#
# Call the Clean UP function
clean_up
Pretty Linux?
Posted by gmconklin in Life and Existence, Systems on October 7, 2010
So what do you think? Is it pretty? LOL 🙂
I guess I should have added how to actually do this… Here is the quick-n-dirty way:
Add the following to the bottom of your .bashrc file for whatever user:
#
alias ls=’ls –color’
LS_COLORS=’di=1;96:fi=0:ln=31:pi=5:so=5:bd=5:cd=5:or=31:mi=0:ex=35:*.rpm=94:*.tar=92:*.sh=32:*.log=91:*.gz=93:*.tgz=93′
export LS_COLOR
Here is a quick legend for the color associations:
di = directory
fi = file
ln = symbolic link
pi = fifo file
so = socket file
bd = block (buffered) special file
cd = character (unbuffered) special file
or = symbolic link pointing to a non-existent file (orphan)
mi = non-existent file pointed to by a symbolic link (visible when you type ls -l)
ex = file which is executable (ie. has ‘x’ set in permissions)
0Â Â = default colour
1Â Â = bold
4Â Â = underlined
5Â Â = flashing text
7Â Â = reverse field
31Â = red
32Â = green
33Â = orange
34Â = blue
35Â = purple
36Â = cyan
37Â = grey
40Â = black background
41Â = red background
42Â = green background
43Â = orange background
44Â = blue background
45Â = purple background
46Â = cyan background
47Â = grey background
90Â = dark grey
91Â = light red
92Â = light green
93Â = yellow
94Â = light blue
95Â = light purple
96Â = turquoise
100 = dark grey background
101 = light red background
102 = light green background
103 = yellow background
104 = light blue background
105 = light purple background
106 = turquoise background
Also, you can combine more than one option per directive like this… *.log=91;1;42 which would give you this: