hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Hosting Security and Technology : Directory Back-Up
Reply

Hosting Security and Technology Configuring and optimizing web hosting servers and operating systems, developing administration scripts, building servers, protecting against hackers, and general security (SSL certificates, etc.)
Forum Jump

Directory Back-Up

Reply Post New Thread In Hosting Security and Technology Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 07-30-2008, 08:13 PM
smkied smkied is offline
Web Hosting Guru
 
Join Date: Apr 2006
Posts: 259

Directory Back-Up


Hello!

I would like to make some kind of script (probably .sh?) that automatically takes a directory, makes a copy of it then makes a gzip tar and then shoots it over to an FTP server. I would like this to happen twice a day (ie. every 12 hours).

How do I go about it? Any help or advice would be greatly appreciated. Thanks!

Reply With Quote


Sponsored Links
  #2  
Old 07-30-2008, 08:30 PM
smkied smkied is offline
Web Hosting Guru
 
Join Date: Apr 2006
Posts: 259
Oh I would also like the file name of the gzip tar to be <sometexthere>-YYYY.MM.DD.TT.TT.bak.tar

So for example:

mydomain-2008.08.01.16.53.bak.tar

Reply With Quote
  #3  
Old 08-05-2008, 11:33 AM
evilghost evilghost is offline
Registered User
 
Join Date: Aug 2008
Posts: 41
Code:
tar --create --gzip --file=- /path/to/directory|ncftpput -c -u username -p password -P 21 ftp.myhost.com /path/to/upload/directory/`date +%Y.%m.%d.%H.%M.%S.bak.tgz`
Then, just 'crontab -e' to schedule the above command accordingly.

Reply With Quote
Sponsored Links
  #4  
Old 08-06-2008, 12:31 AM
LnxtecH LnxtecH is offline
Web Hosting Evangelist
 
Join Date: Jul 2005
Posts: 470
You may copy the script below to /etc/cron.daily

Quote:
#!/bin/bash

FTP_HOSTNAME='Give remote ftp hostname here';
FTP_USERNAME='Give ftp username here';
FTP_PASSWORD='give ftp password here';
LOCAL_DIR='path to the folder to be backed up';
REMOTE_DIR='Relative path of the Remote folder where the backups are to be stored';

FILE_NAME=backup-`date +%d-%m-%y`.tar.gz;

# Tar the Directory
tar -zcvf $FILE_NAME $LOCAL_DIR;

#FTP the tar backup to the remote server.

ftp -n $FTP_HOSTNAME << EOF
quote USER $FTP_USERNAME
quote PASS $FTP_PASSWORD
cd $REMOTE_DIR
put $FILE_NAME
quit
EOF

# Remove the local tar file
rm -f $FILE_NAME;
exit;

Reply With Quote
  #5  
Old 08-06-2008, 12:52 AM
CodyRo CodyRo is online now
Web Hosting Master
 
Join Date: Feb 2006
Location: Buffalo NY
Posts: 1,146
I would recommend SCP over FTP .. or even SFTP.

__________________
Cody R. - Chief Technical Officer
Quality Shared and VPS Hosting
Hawk Host Inc. Proudly serving websites since 2004
PHP 5.3 & PHP 5.4 Support!

Reply With Quote
  #6  
Old 08-06-2008, 02:49 PM
smkied smkied is offline
Web Hosting Guru
 
Join Date: Apr 2006
Posts: 259
Thanks for all the input!

When I run the script as root, I get:

-bash: ./backup.cron: Permission denied

Any suggestions?

Reply With Quote
  #7  
Old 08-06-2008, 02:51 PM
evilghost evilghost is offline
Registered User
 
Join Date: Aug 2008
Posts: 41
chmod +x ./backup.cron

Reply With Quote
  #8  
Old 08-06-2008, 06:16 PM
balajee balajee is offline
Newbie
 
Join Date: Jul 2008
Posts: 11
highly recommend SCP transfer. You could share the keys of SSH between the servers to skip the authentication while transferring the data.

Reply With Quote
  #9  
Old 08-06-2008, 06:19 PM
smkied smkied is offline
Web Hosting Guru
 
Join Date: Apr 2006
Posts: 259
The problem is that the destination server doesn't give me SSH or SSL. It's just a basic shared web hosting account, so SFTP is definitely out of the question.

Reply With Quote
  #10  
Old 08-06-2008, 06:33 PM
balajee balajee is offline
Newbie
 
Join Date: Jul 2008
Posts: 11
probably this is time for all hosting providers to start giving SSH/SCP. In the mean time FTP looks like the only option available.

Reply With Quote
  #11  
Old 08-06-2008, 07:01 PM
smkied smkied is offline
Web Hosting Guru
 
Join Date: Apr 2006
Posts: 259
Hmmm so now, after doing chmod +x, when I try to run the script I get this:

[root@srv01 cron.daily]# ./backup.cron
tar: Removing leading `/' from member names

And then it goes on to show like a whole list of the contents of that directory and stuff, but doesn't actually do any backing-up. What's going on?

Reply With Quote
  #12  
Old 08-07-2008, 12:56 AM
LnxtecH LnxtecH is offline
Web Hosting Evangelist
 
Join Date: Jul 2005
Posts: 470
That message is from the tar command and its normal. If there are no other errors then I can assure its working.

Have you checked the remote directory in the FTP server? Can you see the tar backup there?

Reply With Quote
  #13  
Old 08-07-2008, 01:05 AM
smkied smkied is offline
Web Hosting Guru
 
Join Date: Apr 2006
Posts: 259
There are no files in the remote FTP.

Reply With Quote
  #14  
Old 08-07-2008, 01:23 AM
LnxtecH LnxtecH is offline
Web Hosting Evangelist
 
Join Date: Jul 2005
Posts: 470
You can catch me at bkays001 (AIM) and I will help you to set up the script.

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
Windows Azure Offers Active Directory in General Availability Web Hosting News 2013-04-09 14:09:20
50c21c1c-1d94-4ed4-adac-26fa45a79943 Listing 2013-03-05 18:26:32
Windows Azure Processes 4.7 Billion Authentication Requests Weekly Web Hosting News 2012-11-27 17:21:03
Web Host Hostway Offers Compliant Ready Upgrade for Hosted Exchange Web Hosting News 2012-07-30 14:26:14
Get listed in WHIR Magazine's 5th Annual Hottest Hosts Issue coming in January 2012 Blog 2011-10-18 18:35:27


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?