View Full Version : Need Help with Backups and Cron Job
Host4Cheap
September 25th, 2006, 06:06
Hi
I need help with Backups and Cronjob. What i am looking for is that, i want a DATABASE backup once a day and the main Public_html backup once in a week.
Th Backup Database should have name like "backup_datemonth.tar.gz" and the Cron job then Save the Backup not on the same server but a another server using FTP. Same goes with Public HTML but that is just to be done once a week.
Can anyone help me :-)
krakjoe
September 25th, 2006, 07:25
Add me to msn, my username at hotmail.com, that sounds pretty easy ....
serverorigin
September 25th, 2006, 16:22
Here ya go:
http://www.0php.com/downloads/MySQL-Backup-Utility.zip
Just unzip it and drop it into your directory.
Host4Cheap
September 26th, 2006, 04:36
Thanks :D but that script is not what i am looking for :P
James
September 26th, 2006, 06:30
Just use the incremental backup of WHM/CPanel and use a scp / rsync command in your crontab.
Hope that's helpful.
Host4Cheap
September 26th, 2006, 09:17
I want do this on my DirectAdmin Reseller Account :P
serverorigin
September 27th, 2006, 00:07
Could also just use DirectAdmin backup and run a cron job to ftp it to a remote site.
Host4Cheap
September 28th, 2006, 03:35
I found this Shell Script
#!/bin/sh
# This script will backup one or more mySQL databases
# and then optionally email them and/or FTP them
# This script will create a different backup file for each database by day of the week
# i.e. 1-dbname1.sql.gz for database=dbname1 on Monday (day=1)
# This is a trick so that you never have more than 7 days worth of backups on your FTP server.
# as the weeks rotate, the files from the same day of the prev week are overwritten.
#/bin/sh /home/user/directory/scriptname.sh > /dev/null
############################################################
#===> site-specific variables - customize for your site
# List all of the MySQL databases that you want to backup in here,
# each seperated by a space
# If not run by root, only one db per script instance
databases=""
# Directory where you want the backup files to be placed
backupdir=
# MySQL dump command, use the full path name here
mysqldumpcmd=/usr/bin/mysqldump
# MySQL Username and password
userpassword=" --user= --password="
# MySQL dump options
dumpoptions=" --quick --add-drop-table --add-locks --extended-insert --lock-tables"
# Unix Commands
gzip=/bin/gzip
uuencode=/usr/bin/uuencode
mail=/bin/mail
# Send Backup? Would you like the backup emailed to you?
# Set to "y" if you do
sendbackup="n"
subject="mySQL Backup"
mailto="me@mydomain.com"
#===> site-specific variables for FTP
ftpbackup="y"
ftpserver=""
ftpuser=""
ftppasswd=""
# If you are keeping the backups in a subdir to your FTP root
ftpdir=""
#===> END site-specific variables - customize for your site
############################################################
# Get the Day of the Week (0-6)
# This allows to save one backup for each day of the week
# Just alter the date command if you want to use a timestamp
DOW=`date +%d-%B`
# Create our backup directory if not already there
mkdir -p ${backupdir}
if [ ! -d ${backupdir} ]
then
echo "Not a directory: ${backupdir}"
exit 1
fi
# Dump all of our databases
echo "Dumping MySQL Databases"
for database in $databases
do
$mysqldumpcmd $userpassword $dumpoptions $database > ${backupdir}/${DOW}-${database}.sql
done
# Compress all of our backup files
echo "Compressing Dump Files"
for database in $databases
do
rm -f ${backupdir}/${DOW}-${database}.sql.gz
$gzip ${backupdir}/${DOW}-${database}.sql
done
# Send the backups via email
if [ $sendbackup = "y" ]
then
for database in $databases
do
$uuencode ${backupdir}/${DOW}-${database}.sql.gz > ${backupdir}/${database}.sql.gz.uu
$mail -s "$subject : $database" $mailto < ${backupdir}/${DOW}-${database}.sql.gz.uu
done
fi
# FTP it to the off-site server
echo "FTP file to $ftpserver FTP server"
if [ $ftpbackup = "y" ]
then
for database in $databases
do
echo "==> ${backupdir}/${DOW}-${database}.sql.gz"
ftp -n $ftpserver <<EOF
user $ftpuser $ftppasswd
bin
prompt
cd $ftpdir
lcd ${backupdir}
put ${DOW}-${database}.sql.gz
quit
EOF
done
fi
# And we're done
ls -l ${backupdir}
echo "Dump Complete!"
exit
Just a few things missing :P
1. Delete the File from the Server after sucessfully FTP it on Remote Server.
2. It cannot Backup and tar.gz the Public_html Dir
Anyhelp shall be appreciated :-)
Powered by vBulletin® Version 4.1.7 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.