LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   help with script (https://www.linuxquestions.org/questions/programming-9/help-with-script-512555/)

activeq 12-21-2006 07:42 AM

help with script
 
Hi,

i'm writing a script to automate a backup for Scalix mailserver.

I'm very basic in writing script so that's why I need some help.

I have this already and it works:


#!/bin/sh

DATE=`date +%d-%m-%y`

mkdir /backup/wednesday/
cd /backup/wednesday/
mkdir $DATE

sxmboxexp --force --user "user1" -a /backup/wednesday/$DATE/user1.mbox
sxmboxexp --force --user "user2" -a /backup/wednesday/$DATE/user2.mbox
sxmboxexp --force --user "user3" -a /backup/wednesday/$DATE/user3.mbox

exit

Actually I want to have a rotation script, but that's too complicated. That's why I thought about automatically removing backups which are older then 7 days old.

I thought this command was ok, but apparently not:

find /backup/wednesday/ -mindepth 7 -atime 1 rm -R {}\;

I get an error message which says:
"paths must precedes expression....."

I can't solve this error.

Please help.

Thanks in advance

kshkid 12-21-2006 08:11 AM

Quote:

find /backup/wednesday/ -mindepth 7 -atime 1 rm -R {}\;
try this,


Code:

find /backup/wednesday/ -mindepth 7 -atime 1 -exec rm -R {}\;

activeq 12-21-2006 08:23 AM

Quote:

Originally Posted by kshkid
try this,


Code:

find /backup/wednesday/ -mindepth 7 -atime 1 -exec rm -R {}\;


it says:

"missing argument to '-exec' "

this is the problem i ran into the beginning.

kshkid 12-21-2006 08:27 AM

space between {} and \

activeq 12-21-2006 09:25 AM

Quote:

Originally Posted by kshkid
space between {} and \


That did the trick.

thanks

fotoguy 01-14-2007 06:20 AM

Here's a script that I wrote ages ago you just need to edit it a bit, it will backup to a cdrom if you need that as well

Code:

#!/bin/sh
###########################################################################
Backup_Dirs="/var/log"
Backup_Dest_Path="/tmp/backup"
Backup_Date=`date +%a%b-%d-%Y-%R`
Backup_Name="Hostname-domainname"
Speed="8"                                # Use best speed for CD-R/RW disks on YOUR system
MAILTO="someone@somewhere.com"
###########################################################################
#        Check to see of backup directory exists, if not then create it
function makeBackupDir {
        if [ ! -d $Backup_Dest_Path ]; then
                mkdir $Backup_Dest_Path
                chmod 700 $Backup_Dest_Path
        fi
}
makeBackupDir
###########################################################################
#        Create tar file with todays Month Day Year prepended for easy identification  and also create a log file
function tarBackupDir {
        echo "Start creating backups including log files"
        tar -cvzpf $Backup_Dest_Path/$Backup_Name-$Backup_Date.tar.gz $Backup_Dirs > $Backup_Dest_Path/$Backup_Name-$Backup_Date.log
        echo "Finished creating backups including log files"
}
tarBackupDir
###########################################################################
#        Create a image that can be written to writeable media
function makeImage {
        echo "Making image file"
        #mkisofs -R -o /tmp/$Backup_Name-$Backup_Date.img $Backup_Dest_Path
        mkisofs -l -r -J -V $Backup_Name-$backup_Date -o /tmp/$Backup_Name-$Backup_Date.iso $Backup_Dest_Path
        echo "Finished making iso file"
}
makeImage
###########################################################################
#        Check size of backup image be for we burn it
function checkSize {
        echo "Check size of file before burning to disc"
        SIZE=`du -m /tmp/$Backup_Name-$Backup_Date.iso | awk '{print $1}'`
        if [ "$SIZE" -lt "700" ]; then
                echo "Size OK to burn"
        else
                echo "Size too big to burn"
                exit 1
        fi
        echo "Finished size checking"
}
checkSize
###########################################################################
#        Burn to disc
function burnImage {
        BURNER=`cdrecord dev=ATAPI -scanbus | grep "'" | awk '{print $1}' | grep "0"`
        echo "Burning back-up to disc."
        cdrecord dev=ATAPI:$BURNER -v blank=fast -eject fs=64M driveropts=burnproof speed=$Speed -sao /tmp/$Backup_Name-$Backup_Date.iso
        echo "Successfully burnt: $Backup_Name-$Backup_Date.iso to disc"
}
burnImage
###########################################################################
#        Mail a backup notice to someone
function mailTo {
        echo "Mail sent to $MAILTO"
        mail -s "$Backup_Name-$Backup_Date: $Size MB : Backup Complete" $MAILTO < /dev/null
}
mailTo
###########################################################################
#        Lets clear out some old backups that are older than 7 days
function cleanUp {
        find $Backup_Dirs -type f -mtime +7 -exec rm -f '{}' \; #Delete logfiles older than 7 days (After backup)
        find $Backup_Dest_Path -type f -exec rm -f '{}' \; #Delete files in backup directory
}
cleanUp
###########################################################################
exit 0
##########################


ygloo 01-14-2007 01:18 PM

#!/bin/sh

DATE=`date +%d-%m-%y`
BACKUP_DIR=/backup/wednesday

mkdir $BACKUP_DIR/$DATE
cd $BACKUP_DIR

sxmboxexp --force --user "user1" -a $BACKUP_DIR/$DATE/user1.mbox
sxmboxexp --force --user "user2" -a $BACKUP_DIR/$DATE/user2.mbox
sxmboxexp --force --user "user3" -a $BACKUP_DIR/$DATE/user3.mbox

find $BACKUP_DIR/$DATE -mindepth 7 -atime +7 -exec rm -R {} \;

exit


All times are GMT -5. The time now is 07:18 AM.