Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Folder Remote Cron Backup with File Management - Bash Code Bank


Folder Remote Cron Backup with File Management
This Bash script packages your important folders into a tarball and puts it to a remote location via ftp.
                #!/bin/bash
#cronbackup version 0.0.01
#created by websniper 1-25-07

############################
#This is a simple shell script that is used to backup important
#folders from the server. It can be run as a cron job.
#The script saves the files that you specify into a tarball that is 
#sent anywhere via ftp. The program also runs file management
#for you. It deletes the oldest backups.
#
#License = Open source baby. Improve it and find me on the web e-mail a copy
#Hint look me up on google related to hacker sites. If you don't find me 
#I will know
############################

# get the dates and put them into variables
bdate=$(date +%F)
bmonth=$(date +%m)
byear=$(date +%Y)

#Define 
lmonth=$(date -d '-1 month' +%m)
lyear=$(date -d '-1 month' +%Y)

# Backup directory to place file in
bakdir=/var/tmp/backup

#Keep only the last day of the last month
rm `ls -t $bakdir/backup.$lyear-$lmonth* | awk 'NR>1'`
#Keep the most recent 4 from this month
rm `ls -t $bakdir/backup.$byear-$bmonth* | awk 'NR>4'`


# what the backup will be called
filename=backup.$bdate.tar.gz
# what dirs to backup seperated by a space
files="/var/www /etc /usr/local/nagios"

tar zcf $bakdir/$filename $files

echo "Backup File Complete"
echo "Starting Transfer"


HOST='happy.domain.net'
USER='admin'
PASSWD='whateveritis'
FILE='$bakdir/$filename'


ftp -n $HOST <<END_SCRIPT
quote user $USER
quote PASS $PASSWD
cd /data/backup
put $bakdir/$filename current-backup.servername.tar.gz
quit
END_SCRIPT

echo "Transfer Complete"

exit 0
            
Comments
Sorry but there are no comments to display