View Single Post
  #4 (permalink)  
Old 27-11-2008, 10:47 PM
nixcraft's Avatar
nixcraft nixcraft is offline
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 245 Times in 184 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Here is a sample shell script:

Code:
#!/bin/bash

# dirs to backups
DIRS="/path/to/events /path/to/marketing"

# Save zip file elsewhere on the server 
DEST="/disk2/archive"



# set to "no" keep old zip file and add new file
DELETE_OLD_ZIP_FILES="yes" 

#Path to binary files
BASENAME=/usr/bin/basename 
ZIP=/usr/bin/zip

for d in $DIRS
do
    zipfile="${DEST}/$(${BASENAME} ${d}).zip"
    echo -n "Creating $zipfile..."
    if [ "$DELETE_OLD_ZIP_FILES" == "yes" ]
    then
        [ -f $zipfile ] && /bin/rm -f $zipfile 
    fi
    # create zip file
    ${ZIP} -r $zipfile $d &>/dev/null && echo "Done!"
done
Save this file to /root/mkserverzip.sh and set cron job as follows to backup it up weekly:
Code:
@weekly /root/mkserverzip.sh
See cron tutorial for more info:
How do I add jobs to cron under Linux or UNIX oses?

Modify script as per your setup.
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help

Last edited by nixcraft; 27-11-2008 at 10:48 PM. Reason: Thread moved to scripting section
Reply With Quote