Highland Linux User Group

Linux Community
It is currently Mon Feb 06, 2012 8:44 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Sync backup your FTP server
PostPosted: Wed Feb 17, 2010 9:02 pm 
Offline
Moderator
User avatar

Joined: Tue Oct 03, 2006 12:27 pm
Posts: 162
Location: Inverness UK
Common back up tool to use in a linux system is Rsync.
It's easy to back up in your server from hard drive to hadrive, but if you want to back up from server A to server B then Rsync doesn't support
i found a solution for this:

Create a file call

.netrc

in the file add this :
Code:
machine ftp.ftpserver.com # replace ftpserver with your ftp server
login  yourusername # Replace yourusername with your user
password  password # Replace password with your own password


now create a file *.sh (ex: backup.sh)
to backup from your ftp server to local machine
add to the file

Code:
#!/bin/bash
copydir --verbose --netrc ftp://yourusername@ftp.ftpserver.com/directosy/from/backup/ /directory/to/backup/


to backup from your local machine to ftp server
add to the file

Code:
#!/bin/bash
copydir --verbose --netrc /directory/from/backup/ ftp://yourusername@ftp.ftpserver.com/directosy/to/backup/


Replace directory to your own back up directories.

to run the backup.sh you either have to set permission for it to be executable by:

chmod r+x backup.sh
type:
./backup.sh

or chmod 755 backup.sh
./backup.sh

or type:
sh ./backup.sh if you dont want to set permission



========================================================================

another solution is using lftp

to use lftp you have to install it.

you can either download source code to compile or download from apt sources.

in this example im using ubuntu as linux server, since ubuntu support apt-get

i only have to type:

#apt-get install lftp
to see manual of lftp type:
#man lftp
or:
#lftp -h
for help
to upload from your ftp server to remote server, you have to create a file with any name, in this example i choose sync_up.txt

vi ./sync_up.txt

add in the file:

Code:
open ftp://username:password@ftp.server.com
mirror -R -v --only-newer /folder/to/upload_from /


to run: lftp -f ./sync_up.txt


to download from remote server i choose sync_down.txt

Quote:
open ftp://username:password@ftp.server.com
mirror -v -c --only-newer /remote/folder/ /home/local/folder/to/backup/


and run similar to sync_up.txt
ex: lftp -f ./sync_down.txt

to see manual don;t forget to type:

man lftp
=========================================

other method is using wget

read here wget-usage-t112.html

_________________
Computers are like air conditioners, They stop working properly when you open Windows!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 18, 2010 3:24 am 
Offline
Moderator
User avatar

Joined: Tue Oct 03, 2006 12:27 pm
Posts: 162
Location: Inverness UK
Quick and easy FTP backup with lftp

No matter what Linux distribution you are using, chances are that you’ll find more than one graphical FTP client in its repositories. But if you are looking for a powerful command-line FTP tool, your best bet is lftp. Of course, you can always use the good old ftp tool, but lftp takes the task of managing files and directories using the FTP protocol onto a whole new level. To get to grips with this excellent tool, let’s use it to write a script that creates a local backup copy of a web site.

To write the script, you need to know how to use lftp to connect to an FTP server and synchronize a remote directory with a local one. If your FTP server supports anonymous connections, you can connect to it using the simple command:
Code:
lftp ftpsite

If the server requires a user name and password, the connection command would look like:
Code:
lftp -u username,password ftpsite.

To synchronize a remote directory with a folder on your hard disk, lftp utilizes the mirror command. Used without switches, this command syncs the current local and remote directories. You can also specify explicitly the source and target directories:

Quote:
mirror path/to/source_directory path/to/target_directory


The mirror command offers a comprehensive set of switches, which you can use to control the synchronization process. For example, used with the –delete switch, the mirror command deletes the files in the local folder that are not present in the remote directory, while the –only-newer option forces lftp to download only newer files. Another handy switch is –exclude; it allows you to specify which files and directories to skip during synchronization. And if you prefer to keep an eye on the syncing process, you can use the –verbose switch.

Typing all those switches every time you want to synchronize two directories can be a bit of a bother. Fortunately, lftp understands complex commands that can perform several actions in one fell swoop. All you have to do is to use the -e switch, so lftp stays connected and runs the specified commands:
Quote:
lftp -u username,password -e "mirror --delete --only-newer --verbose path/to/source_directory path/to/target_directory" ftpsite


Using this command, lftp connects to the FTP server using the provided credentials, and then runs the command(s) in the quotes. You can save the entire command in a text file, then run it by pointing lftp to it using the -f switch:

Quote:
lftp -f /home/user/ftpscript.txt


lftp has a few other clever tricks up its sleeve. The at switch can come in handy when you want to run the backup at a specific time. The following command, for example, runs at midnight:

Quote:
lftp at 00:00 -u username,password -e "mirror --delete --only-newer --verbose path/to/source_directory path/to/target_directory" ftpsite &

Notice the ampersand, which sends the command to the background so you don’t have to keep the terminal window open.

Now you know how to create local backup of files and directories stored on an FTP server. But how do you restore the data if disaster strikes? Quite easily, actually. All you have to do is to add the –reverse switch to the mirror command:
Quote:
lftp -u username,password -e "mirror --reverse --delete --only-newer --verbose path/to/source_directory path/to/target_directory" ftpsite

As the name suggests, the switch reverses the source and target directories, so lftp uploads files from the local directory to the remote FTP server.

That’s all there is to it. Check lftp’s man pages to get an overview of lftp’s other useful options, and start FTPing like a pro.

_________________
Computers are like air conditioners, They stop working properly when you open Windows!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2010 Highlands Linux Users Group