Posts Tagged report

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

Advertisements

, , , , , , , , , , ,

Leave a comment

Zimbra anyone?


I used to work in an environment that required a great deal of attention to the maildrops within the infrastructure… Not a big deal aside from the fact that I knew nothing about Zimbra…. LOL (go figure right) or really anything about mail on this scale.¬† I think they had somewhere in the neighborhood of 3+ million users.¬† So in lieu of actually learning anything, (really it was a time issue, I just had to know what to do) I was able to compile a bunch of useful one-liners to tell me everything I needed to know, on demand.¬† So here it is, for anyone who uses Zimbra, I found this to be an invaluable asset, especially @ 3:00AM, being awakened from a dead sleep to solve space issues on maildrops in less than 15 minutes (the SLA, a-holes…). basically this loops though all the maildrops and prints the output on-screen showing the current new user creation MD (so that you don’t move more users there) and specifics about each MD that would allow you to best choose where to move users.¬† Possibly a space allocation in the contract would have resolved this issue (who the hell has unlimited space for emails?), but hey anything for the sale right? F’ing morons… Suffice it to say that I (well the entire team) spent a great deal of time deciding where to move users because there was no more disk space available… on a daily basis. LOL… I sure don’t miss those calls…

Legend:

sortaroot = a created user account with elevated access and rsa keys for looping purposes.

Did you get the peter.inatech.com? Wow… right…

# automate some preliminary maildrop checks before moving users
#
# Source the machines file
source /etc/inatech/machines
#
# Verify all maildrop file systems

DATE=`date +%Y-%m-%d`
created=”`sudo su – sortaroot -c “ssh md112.peter sudo ‘/opt/zimbra/bin/zmprov gc peter | grep -i mailhostpool|cut -c21-56′”`”
echo “”
echo “The following string will determine which mail drop”
echo “is currently defined for new user creation: $created”
# Formatting
echo “”
echo “Mail Drop¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† Size¬† Used Avail Use% Mounted on¬†¬†¬†¬†¬†¬†¬†¬†¬† Number of users¬†¬† Maildrop in which new users are being created ”
echo “————————————————————————————————————————————”

for i in $MD
do printf “$i.peter.inatech.com”
mail=`sudo su – sortaroot -c “ssh -o connectTimeout=5 $i.peter df -kh |grep ‘/opt/zimbra/store’| cut -c20-61″`
nuser=`sudo su – sortaroot -c “ssh -o connectTimeout=5 $i.peter zcat /var/tmp/$i.quota.$DATE | wc -l”`
crfind=`sudo su – sortaroot -c “ssh -o connectTimeout=5 $i.peter sudo ‘/opt/zimbra/bin/zmprov gs $i.peter.inatech.com | grep “$created”‘”`
echo “$mail¬†¬† $nuser¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† $crfind”
done
#
# END

, , , , , , , , , ,

1 Comment