Backup Site Recursively from FTP with Wget

Backing up your WebSite is a necessary step for all users.

This article describes how to recursively download your WebSite with all files, directories and sub-directories from FTP server, using Wget utility.

First of all create a folder in which you are going to download a site. For example, let’s create the folder backups in a home directory.

# mkdir ~/backups
# cd ~/backups

Download Entire Site from FTP

The following command recursively downloads your site with all its files and folders from FTP server and saves them to the current directory.

# wget -r -l 0 -nH ftp://user:pass@ftp.server.com
Option Description
user FTP username
pass FTP password
ftp.server.com IP address or domain name of an FTP server
-r, –recursive Recursive retrieving
-l, –level Maximum recursion depth (0 = unlimit)
-nH, –no-host-directories Disable generation of host-prefixed directories

Your site has been downloaded:

# ls -l
drwxr-xr-x 4 user group 4096 2013-05-09 18:20 yoursite.com

Backup Downloaded Site

Now you can compress the folder with your site as follows:

# tar -czf site-backup-$(date +%Y%m%d-%H%M%S).tar.gz yoursite.com

The previous command creates an archive, named something like site-backup-20130509-190638.tar.gz.

To extract the archive, type:

# tar -zxvf site-backup-20130509-190638.tar.gz

Download a Particular Folder from FTP

Let’s say we have the following structure in FTP home directory:

/yoursite.com/www/images

The following command recursively downloads ‘images’ folder, with all its content from FTP server and saves it to the current directory.

# wget -r -l 0 -nH -np --cut-dirs=2 ftp://user:pass@ftp.server.com/yoursite.com/www/images
Option Description
-np, –no-parent Don’t ascend to the parent directory
–cut-dirs Ignore ‘number’ parent directories

All these tasks have to be automated and added to Cron. The HowTo is coming …

What is my Public IP address?

Use one of the following commands to check your public IP address from the Linux command line.

Get the Public IP address from the Linux Command Line

0. Easy to Remember Services

Get your external IP address using the curl command:

$ curl ifconfig.me
$ curl ip.appspot.com
$ curl icanhazip.com

Get your external IP address using the wget command:

$ wget -q -O - ifconfig.me
$ wget -q -O - ip.appspot.com
$ wget -q -O - icanhazip.com

Get the External IP address using DynDNS.org

1. Using the wget command:

$ wget -q -O - checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//'

2. Using the curl command:

$ curl -s checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//'

3. Using the lynx command:

$ lynx -dump checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//' | sed '/^$/d'