#!/bin/sh tdate=`date +%Y%m%d-%H%M%S` BACKUP_PATH="backup" SUBDIR="/pgsql" echo $tdate: backup of "$3"... if [ $# -ne 4 ] then echo "Bad arguments" echo "---------------------------------------------------------------------" echo "USAGE : pgdump.sh " echo "---------------------------------------------------------------------" exit 1 else fname=$tdate-$1-$3.backup dname=`date +%Y-%m-%d` if [ -d $BACKUP_PATH ] then if [ -d "$BACKUP_PATH/$dname" ] then if [ -d "$BACKUP_PATH/$dname$SUBDIR" ] then if [ -f "$BACKUP_PATH/$dname$SUBDIR/$fname" ] then dialog --title "Confirm File Replace" --backtitle "pgdump.sh"\ --yesno "\nFile already exist, Do you want to replace it with '$BACKUP_PATH/$dname$SUBDIR/$fname' file" 7 90 sel=$? case $sel in #if Yes then replace the file with new dump file 0) pg_dump $3 -f $BACKUP_PATH/$dname$SUBDIR/$fname -h $1 -U $2 -i -x -O -b -F c;; #if No then exit 1) exit 1 ;; #if escape thenexit 255) exit 1;; esac else pg_dump $3 -f $BACKUP_PATH/$dname$SUBDIR/$fname -h $1 -U $2 -i -x -O -b -F c fi else mkdir $BACKUP_PATH/$dname$SUBDIR pg_dump $3 -f $BACKUP_PATH/$dname$SUBDIR/$fname -h $1 -U $2 -i -x -O -b -F c #if databse to take does not exist then Delete the folder created if [ $? -ne 0 ] then rmdir $BACKUP_PATH/$dname$SUBDIR rmdir $BACKUP_PATH/$dname fi fi else mkdir $BACKUP_PATH/$dname if [ ! -d "$BACKUP_PATH/$dname$SUBDIR" ] then mkdir $BACKUP_PATH/$dname$SUBDIR fi pg_dump $3 -f $BACKUP_PATH/$dname$SUBDIR/$fname -h $1 -U $2 -i -x -O -b -F c #if databse to take does not exist then Delete the folder created if [ $? -ne 0 ] then rmdir $BACKUP_PATH/$dname$SUBDIR rmdir $BACKUP_PATH/$dname fi fi else mkdir $BACKUP_PATH mkdir $BACKUP_PATH/$dname if [ ! -d "$BACKUP_PATH/$dname$SUBDIR" ] then mkdir $BACKUP_PATH/$dname$SUBDIR fi pg_dump $3 -f $BACKUP_PATH/$dname$SUBDIR/$fname -h $1 -U $2 -i -x -O -b -F c #if databse to take does not exist then Delete the folder created if [ $? -ne 0 ] then rmdir $BACKUP_PATH/$dname$SUBDIR fi fi echo ...done ######################################## # Copy and zip all databases and files # ######################################## #tdate=`date +%Y%m%d-%H%M%S` COPY_PATH=$4 PREFIX_PATH="" POSTFIX_PATH="" BIN_PATH="" #Create folders for archives if [ ! -d $BACKUP_PATH/$dname/www ] then mkdir $BACKUP_PATH/$dname/www fi #Backup and zip files a1=${COPY_PATH%${POSTFIX_PATH}} filename="files" echo "$COPY_PATH -> $BACKUP_PATH/$dname/www/$tdate-www-$filename.zip" zip -r $BACKUP_PATH/$dname/www/$tdate-www-$filename.zip $COPY_PATH fi #End