This is a simple backup solution for people who run their own web server and MySQL database server on a dedicated or VPS server. Most dedicated hosting provider provides backup service using NAS or FTP servers. These service providers will hook you to their redundant centralized storage array over private VLAN. Since, I manage couple of boxes, here is my own automated solution. If you just want a shell script, go here (you just need to provided appropriate input and it will generate FTP backup script for you on fly, you can also grab my php script generator code).
Making Incremental Backups With tar
You can make tape backups. However, sometime tape is not an option. GNU tar allows you to make incremental backups with -g option. In this example, tar command will make incremental backup of /var/www/html, /home, and /etc directories, run:
# tar -g /var/log/tar-incremental.log -zcvf /backup/today.tar.gz /var/www/html /home /etc
Where,
- -g: Create/list/extract new GNU-format incremental backup and store information to /var/log/tar-incremental.log file.
Making MySQL Databases Backup
mysqldump is a client program for dumping or backing up mysql databases, tables and data. For example, the following command displays the list of databases:
$ mysql -u root -h localhost -p -Bse 'show databases'
Output:
Enter password: brutelog cake faqs mysql phpads snews test tmp van wp
Next, you can backup each database with the mysqldump command:
$ mysqldump -u root -h localhost -pmypassword faqs | gzip -9 > faqs-db.sql.gz
Creating A Simple Backup System For Your Installation
The main advantage of using FTP or NAS backup is a protection from data loss. You can use various protocols to backup data:
- FTP
- SSH
- RSYNC
- Other Commercial solutions
However, I am going to write about FTP backup solution here. The idea is as follows:
- Make a full backup every Sunday night i.e. backup everything every Sunday
- Next backup only those files that has been modified since the full backup (incremental backup).
- This is a seven-day backup cycle.
Our Sample Setup
Your-server ===> ftp/nas server IP:202.54.1.10 ===> 208.111.2.5
Let us assume that your ftp login details are as follows:
- FTP server IP: 208.111.2.5
- FTP Username: nixcraft
- FTP Password: somepassword
- FTP Directory: /home/nixcraft (or /)
You store all data as follows:
=> /home/nixcraft/full/mm-dd-yy/files - Full backup
=> /home/nixcraft/incremental/mm-dd-yy/files - Incremental backup
Automating Backup With tar
Now, you know how to backup files and mysql databases using the tar and mysqldump commands. It is time to write a shell script that will automate entire procedure:
- First, our script will collect all data from both MySQL database server and file system into a temporary directory called /backup using a tar command.
- Next, script will login to your ftp server and create a directory structure as discussed above.
- Script will dump all files from /backup to the ftp server.
- Script will remove temporary backup from /backup directory.
- Script will send you an email notification if ftp backups failed due to any reason.
You must have the following commands installed (use yum or apt-get package manager to install ftp client called ncftp):
- ncftp ftp client
- mysqldump command
- GNU tar command
Here is the sample script:
#!/bin/sh # System + MySQL backup script # Full backup day - Sun (rest of the day do incremental backup) # Copyright (c) 2005-2006 nixCraft <http://www.cyberciti.biz/fb/> # This script is licensed under GNU GPL version 2.0 or above # Automatically generated by http://bash.cyberciti.biz/backup/wizard-ftp-script.php # --------------------------------------------------------------------- ### System Setup ### DIRS="/home /etc /var/www" BACKUP=/tmp/backup.$$ NOW=$(date +"%d-%m-%Y") INCFILE="/root/tar-inc-backup.dat" DAY=$(date +"%a") FULLBACKUP="Sun" ### MySQL Setup ### MUSER="admin" MPASS="mysqladminpassword" MHOST="localhost" MYSQL="$(which mysql)" MYSQLDUMP="$(which mysqldump)" GZIP="$(which gzip)" ### FTP server Setup ### FTPD="/home/vivek/incremental" FTPU="vivek" FTPP="ftppassword" FTPS="208.111.11.2" NCFTP="$(which ncftpput)" ### Other stuff ### EMAILID="admin@theos.in" ### Start Backup for file system ### [ ! -d $BACKUP ] && mkdir -p $BACKUP || : ### See if we want to make a full backup ### if [ "$DAY" == "$FULLBACKUP" ]; then FTPD="/home/vivek/full" FILE="fs-full-$NOW.tar.gz" tar -zcvf $BACKUP/$FILE $DIRS else i=$(date +"%Hh%Mm%Ss") FILE="fs-i-$NOW-$i.tar.gz" tar -g $INCFILE -zcvf $BACKUP/$FILE $DIRS fi ### Start MySQL Backup ### # Get all databases name DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')" for db in $DBS do FILE=$BACKUP/mysql-$db.$NOW-$(date +"%T").gz $MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE done ### Dump backup using FTP ### #Start FTP backup using ncftp ncftp -u"$FTPU" -p"$FTPP" $FTPS<<EOF mkdir $FTPD mkdir $FTPD/$NOW cd $FTPD/$NOW lcd $BACKUP mput * quit EOF ### Find out if ftp backup failed or not ### if [ "$?" == "0" ]; then rm -f $BACKUP/* else T=/tmp/backup.fail echo "Date: $(date)">$T echo "Hostname: $(hostname)" >>$T echo "Backup failed" >>$T mail -s "BACKUP FAILED" "$EMAILID" <$T rm -f $T fi
How Do I Setup a Cron Job To Backup Data Automatically?
Just add cron job as per your requirements:
13 0 * * * /home/admin/bin/ftpbackup.sh >/dev/null 2>&1
Generate FTP backup script
Since I setup many Linux boxes, here is my own FTP backup script generator. You just need to provided appropriate input and it will generate FTP backup script for you on fly.
Featured Articles:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- 10 Greatest Open Source Software Of 2009
- My 10 UNIX Command Line Mistakes
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Linux Video Editor Software
- Email this to a friend
- Download PDF version
- Printable version
- Comment RSS feed
- Last Updated: Jan/22/2010



{ 1 trackback }
{ 72 comments… read them below or add one }
On the mysqldump, there’s a -A option to do all databases at once (and –opt to make things more efficient). As you get a bigger database, look at mysqlhotcopy, only good for MyIASM tables but it’s a lot faster than mysqldumping.
Sean
Sean,
I agree with you -opt is a nice option that adds locking and does extended insert and other stuff. I will update the script with -opt option.
-A is good option but I prefer to backup individual database, as it offers the option of restoring individual databases.
mysqldump –help says –opt option is Enabled by default :) so no need to change script
Appreciate your post.
Why is the size of the files created using mysqldump are far more than the database files itself?
Rather if someone simply copies all database files to the backup directory..is there any harm…jst a question…
SaM,
You need to compress sql files using gunzip or other available utilities.
mysqldump makes it easy to move data from one server to another.
Hope this helps
Nix,
You may be right… but I am using a bit un-usual way of backing up tha data.. what I have done is that, I have created the database structure sql file of all that dtabases we are using. And copies the data files on regular basis.
when it comes to retrieve the data, its a simple copy operation…off-cource need to change the ownership to mysql:mysql.
In case I need to trash the datanase and recreate the database, i have the sql file of the structures.
mysqldump also generates database, table structure along with data. Try out mysqldump command any one of the database you will see the difference.
This script does ftp and e-mail backups.
Sorry, here is the link
http://worldcommunity.com/opensource/utilities/mysql_backup.html
Another good solution for MySQL database backup is “AutoMySQL Backup” . It does all the things you need for daily backup.
http://members.lycos.co.uk/wipe_out/automysqlbackup/
jishin,
Thanks for autmmysqlbackup script link :)
Thanks for the script. I’ll give it a whirl.
if i also want to enter into database in this command “$ mysql -u root -h localhost -p -Bse ’show databases’” what can i do??
What about MySQLDumper? (backup, restore, FTP, mail, multipart, …)
Well the bad thing is the vulnerabilities, like the common XSS thing:
http://secunia.com/product/12282/?task=advisories
nixcraft, your script backs-up everything needed for my setup. It was instant success using the generator.
Thank-you
Shaun Prince
Thanks for the script, is brilliant and does exactly what i need it to do.
Just one slight real easy thing i’m sure, but how can i set the FTP port rather than using the standard port 21. If i ncftp manually, i can specify the -P option. Is it easy to put in the script?
Thank you for the script.
So I backed up my MySQL database. How do I restore it? I have a mybackup.sql.gzip in my home. What do I do to restore it?
Can I restore it to another machine with the same MySQL Version?
Type the following commands restore the same:
gunzip mybackup.sql.gzipmysql -u USER -p dbname < mybackup.sql
You can copy file mybackup.sql.gzip using scp to another machine:
scp mybackup.sql.gzip user@machinetwo:/tmpLogin to machinetwo:
cd /tmp
gunzip mybackup.sql.gzip
mysql -u USER -p dbname < mybackup.sql
rm mybackup.sql
Further readings
(a) How can I restore a backup of a MySQL database?
(b) Copy MySQL database from one server to another remote server
HTH
Hi,
this is very nice but i get the following errors:
[: 47: ==: unexpected operator
at the start of the script
and
[: 79: ==: unexpected operator
at the end
therefor I always get email with BACKUP FAILED!.\
Line 47 is “fi”
and Line 79 is the last “fi” at the very end.
Thanx
Copy and paste script again from wizard
HTH
Thanx for the reply but I had more troubles
with the long names with the mysqldump.
Filezilla Server did not like the
(mysql-LongDBname.$NOW-$(date +”%T”).gz) but was very happy when I took out the $(date +”%T”) part, which is fine with me I don’t care for the exact time so much.
For the unexpected operator Error:
I have the feeling that the == sign is not the case with “$var1″ == “$var2″.
Therefore my system was complaining for syntax error(Ubuntu Server 7.04).
From what I have seen on the net:
you can say “$var1″ = “$var2″ OR $var1 == $var2.
I haven’t taste the second option myself.
But the first behaves very nice.
Finally I just took out the -g option from tar because I could not restore from a windows machine when I try it.
7zip could not understand the archive and could not extract the contents.
Lastly I added a Open Ldap database backup too, and send a mail also in success!. I simply wanna know what is is happening with the backup process.
Here it is now:
#!/bin/sh
### System Setup ###
DIRS="/etc /srv/www /var/www /home"
BACKUP="/tmp/backup.${$}"
NOW=$(date +%d-%m-%Y)
INCFILE="/root/tar-inc-backup.dat"
DAY=$(date +%a)
FULLBACKUP="Fri"
### MySQL Setup ###
MUSER="user"
MPASS="passwd"
MHOST="localhost"
### FTP server Setup ###
FTPD="/backup/Ubuntu-Server/incremental"
FTPU="user"
FTPP="passwd"
FTPS="192.168.2.50"
NCFTP=$(which ncftpput)
### Other stuff ###
EMAILID="user@domain.com"
### Start Backup for file system ###
[ ! -d $BACKUP ] && mkdir -p $BACKUP || :
### See if we want to make a full backup ###
if [ "$DAY" = "$FULLBACKUP" ];.
then
FTPD="/backup/Ubuntu-Server/full"
FILE="fs-full-${NOW}.tar.gz"
tar -zcvf $BACKUP/$FILE $DIRS
else
i=$(date +%Hh%Mm%Ss)
FILE="fs-i-${NOW}-${i}.tar.gz"
tar zcvf $BACKUP/$FILE $DIRS
fi
### Start MySQL Backup ###
# Get all databases name
DBS="$(mysql -u ${MUSER} -h ${MHOST} -p${MPASS} -Bse 'show databases')"
for db in $DBS
do
FILE=$BACKUP/mysql-$db.$NOW.gz
mysqldump -u $MUSER -h $MHOST -p$MPASS $db | gzip -9 > $FILE.
done
##Backup the Ldap Directory Database
slapcat -v -n 1 -l $BACKUP/LdapDirectory.ldif
## Dump backup using FTP ###
#Start FTP backup using ncftp
ncftp -u$FTPU -p$FTPP $FTPS$T
echo "Hostname: $(hostname)" >>$T
echo "Backup succesfully Completed!" >>$T
mail -s "BACKUP COMPLETED" "$EMAILID" $T
echo "Hostname: $(hostname)" >>$T
echo "Backup failed" >>$T
mail -s "BACKUP FAILED" "$EMAILID"
Cheers A.
Sorry Here is the complete script hope this time is posted clear.
#!/bin/sh### System Setup ###
DIRS="/etc /srv/www /var/www /home"
BACKUP="/tmp/backup.${$}"
NOW=$(date +%d-%m-%Y)
INCFILE="/root/tar-inc-backup.dat"
DAY=$(date +%a)
FULLBACKUP="Fri"
### MySQL Setup ###
MUSER="user"
MPASS="passwd"
MHOST="localhost"
### FTP server Setup ###
FTPD="/backup/Ubuntu-Server/incremental"
FTPU="user"
FTPP="passwd"
FTPS="192.168.2.50"
NCFTP=$(which ncftpput)
### Other stuff ###
EMAILID="user@domain.com"
### Start Backup for file system ###
[ ! -d $BACKUP ] && mkdir -p $BACKUP || :
### See if we want to make a full backup ###
if [ "$DAY" = "$FULLBACKUP" ];.
then
FTPD="/backup/Ubuntu-Server/full"
FILE="fs-full-${NOW}.tar.gz"
tar -zcvf $BACKUP/$FILE $DIRS
else
i=$(date +%Hh%Mm%Ss)
FILE="fs-i-${NOW}-${i}.tar.gz"
tar zcvf $BACKUP/$FILE $DIRS
fi
### Start MySQL Backup ###
# Get all databases name
DBS="$(mysql -u ${MUSER} -h ${MHOST} -p${MPASS} -Bse 'show databases')"
for db in $DBS
do
FILE=$BACKUP/mysql-$db.$NOW.gz
mysqldump -u $MUSER -h $MHOST -p$MPASS $db | gzip -9 > $FILE.
done
##Backup the Ldpa Directory Database
slapcat -v -n 1 -l $BACKUP/LdapDirectory.ldif
## Dump backup using FTP ###
#Start FTP backup using ncftp
ncftp -u$FTPU -p$FTPP $FTPS$T
echo "Hostname: $(hostname)" >>$T
echo "Backup succesfully Completed!" >>$T
mail -s "BACKUP COMPLETED" "$EMAILID" $T
echo "Hostname: $(hostname)" >>$T
echo "Backup failed" >>$T
mail -s "BACKUP FAILED" "$EMAILID"
However you got the my point!
maybe cut it in pieces
#!/bin/sh### System Setup ###
DIRS="/etc /srv/www /var/www /home"
BACKUP="/tmp/backup.${$}"
NOW=$(date +%d-%m-%Y)
INCFILE="/root/tar-inc-backup.dat"
DAY=$(date +%a)
FULLBACKUP="Fri"
### MySQL Setup ###
MUSER="user"
MPASS="passwd"
MHOST="localhost"
### FTP server Setup ###
FTPD="/backup/Ubuntu-Server/incremental"
FTPU="user"
FTPP="passwd"
FTPS="192.168.2.50"
NCFTP=$(which ncftpput)
### Other stuff ###
EMAILID="user@domain.com"
### Start Backup for file system ###
[ ! -d $BACKUP ] && mkdir -p $BACKUP || :
### See if we want to make a full backup ###
if [ "$DAY" = "$FULLBACKUP" ];.
then
FTPD="/backup/Ubuntu-Server/full"
FILE="fs-full-${NOW}.tar.gz"
tar -zcvf $BACKUP/$FILE $DIRS
else
i=$(date +%Hh%Mm%Ss)
FILE="fs-i-${NOW}-${i}.tar.gz"
tar zcvf $BACKUP/$FILE $DIRS
fi
And the Second part:
### Start MySQL Backup #### Get all databases name
DBS="$(mysql -u ${MUSER} -h ${MHOST} -p${MPASS} -Bse 'show databases')"
for db in $DBS
do
FILE=$BACKUP/mysql-$db.$NOW.gz
mysqldump -u $MUSER -h $MHOST -p$MPASS $db | gzip -9 > $FILE.
done
##Backup the Ldap Directory Database
slapcat -v -n 1 -l $BACKUP/LdapDirectory.ldif
## Dump backup using FTP ###
#Start FTP backup using ncftp
ncftp -u$FTPU -p$FTPP $FTPS
And the Third Part:
### Find out if ftp backup failed or not ###if [ "$?"="0" ];.
then
rm -f $BACKUP/*
echo "Date: $(date)">$T
echo "Hostname: $(hostname)" >>$T
echo "Backup succesfully Completed!" >>$T
mail -s "BACKUP COMPLETED" "$EMAILID" $T
echo "Hostname: $(hostname)" >>$T
echo "Backup failed" >>$T
mail -s "BACKUP FAILED" "$EMAILID"
Hope now it works to see the hole script.
About date localization
The command DAY=$(date +%a) is sensible to the system language,
I prefer to use DAY=$(date +%u) to know the number of the day of the week
I was looking for something like this…
just one question: to send the email of a failed backup what program do I have installed in my pc?
Thankyou
dk,
use normal unix mail command
Thanks for the info.. just wondering, does it work with a regular ftp client? I’m on a shared hosting shell account and it doesn’t look like ncftp is installed.
Hi!
Thank you for this nice tutorial!!
I have a setup with 2 HDDs, having the second as active mysql database storage and another partition for this backup script.
I have modified it to just move the files to the second HDD instead of transfering via FTP and made it so that folders with $NOW are created before moving.
I am wondering how the $INCFILE works? If i want to restore the “fs” from a week before, do i have to use the initial (bigger) TAR which is in the first folder, or does it work with the smaller ones that are i.e. in the folder of today?
You need to restore the last full backup first (
$FULLBACKUP day), followed by each of the subsequent incremental backups to the present day in the correct order.
Here’s a script that can transfer all mysql databases to another server.
Hello,
When I run this script from the command line it works fine but when I run it as a cron job, the FTP connection seems to drop at some point and not all files are not copied over. The FTP server says “disconnected” so as ncftp client logs.
It happens all the time and it is a bit weird. Any clues?
Thanks,G
Heelo,
tks for the script.
I have a problem when running the script with a cron job, it will do the backup but it will not upload via ftp. Any idea why?
Best regards,
Nuno
Why not try to use mysqlhotcopy to make a backup
This looks great, but in Ubuntu 7.10, ncftp isn’t working.
the command
ncftp -u”$FTPU” -p”$FTPP” $FTPS<
gives an error:
wwwbackup.sh: 53: Syntax error: newline unexpected
If I remove the < at the end, it will log in, but then it won’t send the commands to ncftp (after NCFTP quits, it will try running those commands on my own shell!)
Are there ny other way to get ncftp to take commands from the shell script?
OK I think I solved my problem by using ncftpput*
I used this line instead of the ncftp lines you have:
ncftpput -u “$FTPU” -p “$FTPP” -m “$FTPS” $FTPD/$NOW $BACKUP/*
and commented out the ncftp command through EOF command.
* by the way, why do you get the path of ncftpput and never use it?
Berto,
It is a bug, I will try to fix it. Thanks for the heads up.
Even more information on my humiliations in Ubuntu:
They made dash the default shell script, not bash!* So you need to specify $!/bin/bash (not $!/bin/sh) for this to work properly. dash also had problems with the equivalency (==) operator at the end.
This will probably fix the ncftp problems, but since I already have ncftpput working, I’ll keep it.
*From http://ubuntuforums.org/showthread.php?t=265391
Firstly, Thank you so much for this script. I’ve learnt so much just from following it through, and it works perfectly on CentOS 4 after installing ncftp.
Is there a way you can tell it to exclude files? For example, I’ve set it to back up the whole of a certain folder, but there is one sub folder within that I do not want backing up… is this possible?
Thanks!
Hi,
I have two questions. I would have multiple databases to back up in most cases, and multiple users assigned to multiple databases. How would that work?
Many thanks!
Ken
I am getting an error
line53: syntax error near unexpected token ‘do
line53: ‘do
Very helpful. I’m experimenting with setting up a couple servers of my own, and this script is exactly what I was looking for. Thanks for sharing.
You can also use:
/usr/bin/md5sum -b $BACKUP/* >$BACKUP/backup$NOW-$i.md5
Between backup and transfer, so you can verify if the files aren’t modified during transfer or something.
This seems to work well, except when I run it it just does incremental backups. Of what, I’m not sure, as there has not been a full backup yet. Invariably it generates just a 48kb file. The database alone should be at least 800kb… Is there any way to force a full backup? How can I check that this script is working properly?
Thanks,
Adrian
Backup is compressed using gzip; just uncompressed and verify data. By default full backup is made on Sunday; Change FULLBACKUP=”Tue” variable.
thank you for a wonderful script. works perfectly
In this:
if [ "$?" == "0" ]; then
you are checking the return of ncftp, but it always returns “0″
I even altered the password to force it to error and still it returned “0″.
Has anyone confirmed that this will show anything other than “0″?
I did this to check before the if statement
echo “Return Code = $?”
for some unknown reason if i run the script manually it works as it should. everything is zipped up and sent to the ftp server.
However if i set up a cron job all the files are zipped up and placed in the /tmp dir (so i know the script is running) but the files are never sent to the ftp server.
i’ve tried this with several ftp servers etc. etc. with no luck.
Thanks heaps. Clever script. Worked fully once I gave mysql user LOCK privileges. Very helpful.
Might suggest putting php.txt link up at top of wizard page. I entered dummy info, not wanting to send IPs and logins to php script. I now have the script itself and could generate again.
Nice work and thanks for sharing.
Hi
Well ncpftp is not available on my hosting I am using this on shared hosting.
I did change the bash script to
### Dump backup using FTP ###
#Start FTP backup using ncftp
#ncftp -u”$FTPU” -p”$FTPP” $FTPS<<EOF
# Login, run get files
ftp -inv $FTPS <<END_SCRIPT
quote USER $FTPU
quote PASS $FTPP
mkdir $FTPD
mkdir $FTPD/$NOW
cd $FTPD/$NOW
lcd $BACKUP
mput *
quit
EOF
Great script, but am having some challenges getting it to work. First I edited the file on a windows machine but that produced a /bin/sh^M error, so I had to change the line endings to just \n instead of \r\n
Then I had to install ncftp
But now I am getting a “username and/or password was not accepted for login” error on the FTP. I know I am inputting the correct details, and have tried several.
When I used Ali’s version, using FTP instead of ncftp I noticed that it seemed to be sending the username as ‘username_’ instead of just ‘username’. Does the script change the details in some way? Any other ideas why I cannot log in with the script?
I would love to get this going!
Thanks
Hmm, don’t know what it did there, putting in that link, but I think you still get the gist of the problem
Using it for a lot of time and still working perfect!
Now I need exclude some dirs, there are a way to exclude directories?
Tnx ;)
I get following error:
line 60: ncftp: command not found
how shall I fix it?
Install ncftp package.
I just use MySQL administrator to run my daily backups. I can’t think of an easier solution. I have over 30 clients on a variety of shared MySQL databases, and VPS databases. I have the task scheduled to run at midnight every night. However I am searching for an automated web server solution for backups. Thus far I haven’t found anything. Would be great if I could find something like norton ghost but works via FTP. Making incremental backups every night. My hosting provider charges $25 / month for FTP backup. Its cheaper to go out and buy a 2 TB hard drives and run your own backups. If anyone has a more user friendly suggestion let me know.
Hi,
I’m having some problem with the script. I seem to be having problem with the ncftp usage.
The backup files are being created on the temp folder however it will not upload it on my FTP and I am receiving the “Failed backup” email.
I run the script and here’s what I’m getting:
–
/var/lib/mysql/eximstats/sends.MYI
/var/lib/mysql/eximstats/smtp.MYD
/var/lib/mysql/eximstats/smtp.MYI
mysqldump: Got error: 1033: Incorrect information in file: ‘./horde/horde_sessionhandler.frm’ when using LOCK TABLES
mysqldump: Got error: 1033: Incorrect information in file: ‘./roundcube/cache.frm’ when using LOCK TABLES
/root/ncftpd-2.8.6/glibc2.5/ncftpd: illegal option — i
Usage: ncftpd [flags]
Optional Flags (usually set in general config file):
-p XX : Use port XX for control connection (and XX – 1 for data).
-n XX[,YY] : Allow maximum of XX concurrent server users (max-users); keep
at least YY processes running to serve users (min-users).
-v : Increase logging verbosity.
-q : Do not echo log messages to the screen.
-Q : Force echo of log messages to the screen, even if not a tty
(Default is to echo automatically if it is a terminal).
-e : Print the detected hostname and exit.
-b : Print the version information and exit.
-d : Run as background daemon.
Exiting.
–
Any help will be greatly appreciated.
Thanks
i using server os my computer particion c & d & e my c driver only 20gb . d& E 120 gb my computer c drive full i compair e drive and c drive how to compair
how to setup the ie7 auto refreshing
friends share with me
how to mysql auto backup setting
i daily setting
FYI. Since my remote FTP is a windows box, file format for the sql backups had to be modified to exclude the colons in the time format. Changed FILE=$BACKUP/mysql-$db.$NOW-$(date +”%T”).gz to FILE=$BACKUP/mysql-$db.$NOW-$(date +”%Hh%Mm%Ss”).gz and now it works great.
Perhaps this will help someone out that has the same issue.
Thanks!
Thank to Ali for modifying this to work with ftp, Ali ftp script above
But I found that my files were coming out corrupt after transfer.
I had to add binary before mput * to switch it to binary mode before transferring the files. Hope this helps someone.
Perfect script generator (and script) thanks a lot NixCraft, just what I was looking for. Saved me my half life! Respect! You rock!
some questions…
# ftp connection drop
What would happen if during the FTP transfer procedure my second server – which receives the transfer of the backed up files – goes down, or drops the FTP connection. Will the whole process be terminated, or will it try to reconnect and try to continue uploading the files? Will I get any notification about any of those? (Sorry if it is obvious, but I am a noob :)
(( My second server is a shared hosting at HostGator, with an unlimited storage plan. Just ideal fore storing the files, but the FTP connection is crappy and fluctuating, sometimes drops because of the heavy shared usage ))
# free space requirements
please correct me (orr approve) if I get it wrong:
the script copies the files directly into the tar-ed gzip-ed archive, so the required free space on the originating server is equal to the space requirement of the gzip-ed files. For instance:
If the size of all my website files (altogether) is 1 GB and i have some smaller mysql (e.g. joomla) databases lets say 100 MB altogether, than i would need approximately 2,2 GB free space to back them up successfully. Is this rule ( [occupied space] x 2 ) a good way to estimate the free space needed for the backup process?
((On my primary server i have very limited space, since it is a virtual server, and the storage enhancement is expensive, so i would like to buy as small storage space as possible ))
Script works perfect. Thanks!
I was only wondering if there is a possibilyt to exclude file extensions like .zip
Thanks for the script – a good starting point for me. I ended up commenting out
#NCFTP="$(which ncftpput)"under FTP server setup and then used the following, as the password kept failing for some reason:### Dump backup using FTP ###
#Start FTP backup using ncftp
#ncftp -u"$FTPU" -p"$FTPP" $FTPS<<EOF
# Login, run get files
ftp -inv <<EOF
open $FTPS
user $FTPU $FTPP
mkdir $FTPD
mkdir $FTPD/$NOW
cd $FTPD/$NOW
lcd $BACKUP
binary
mput *
quit
EOF
sir how to configure ftp server
Hi,
The backup script is great. But i have very limited space in the ftp backup. If there a way to have an addon to the script to remove old backups and keep 7 incremental backups and 4 weekly backups?
Ok, I am at a loss. First, thanks for the great script. I think it will do wonders for me once I have it up and running.
My fs-i tar’s transfer just great. They complete, and it begins to transfer mysql.XX-XX-2010-HH:MM;SS.gz and finally I get an error “lost data connection to remote host: Broken pipe.”
Then it tries to tranfer others and i get a “put *: could not send file to remote host.” error.
Any tips?
This is fine but doesn’t mysqldump stop the databse from being upated? What if we have a very busy site and can not stop mysqld or allow the db to be blocked? What solutions are there for a hot backup?
Use LVM snapshots or specialized backup software such as zmanda open source or enterprise.
@Michael, a few ftp servers do not allow special characters in a file name. Update the following line to remove %T part and try again:
i.e. set time in hour_minute_seconds_am_OR_pm format
BRILLIANT!!! That did the trick! BTW, the server I was FTPing to was using FIleZilla server, if anyone else has this problem!
Hi,
I have a server with a lot of domains and a bigger space ocupied. I want to make something like this batch but I need a separated tar file per domain.
I have a vhost directory with a various subdirectoris (one per domain), ¿is it possible, with tar, to make one different file per directory?
Sorry for my poor english :-(