Introduction:

What we need, to make this thing working is:

root access via ssh, to our web server, where our site(s) is(are) - for this, we can use putty, for example.
Windows based system (another server or home PC)
Windows 2008, 2003, or windows XP/7/Vista
WinSCP (download link provided in manual)

We also need a basic knowledge about ssh and of course, to install a simple program like WinSCP
Manual is really simple and straight forward, with all necessary links included, it is made by n00b, for n00bs

Part 1 - Making automated backup of wordpress blog


Open shh, login, and for the sake of example, lets say you have complete root access, and your folder is:

/home/admin/


inside of that folder, there could be your wordpress website, named
/home/admin/blabla (just example)

Don't go in your "blabla" folder
create folder named backup in home/admin/ with command:

Code: 
mkdir backup
so you get /home/admin/backup/

And make a folder, where you will keep your script, that will backup things for you

Code: 
mkdir scripts
Enter that folder with command:

Code: 
cd scripts
And you got /home/admin/scripts

Time to make a backup script

type this into your cmd line:

Code: 
vi blabla.script
Text editor will open up, press " i " on your keyboard, to enter edit mode, now your screen looks something like this:



you are sure you did all good, if on the bottom it says INSERT


Now, you can copy this piece of script in notepad, on your home desktop, open your wp-config.php, from your wordpress website, to see necessary details, in case you don't already have them somewhere, like on the image:




and enter them properly, only bold parts are the ones you need to replace

Code: 
#!/bin/bash
MYSQL_USERNAME=sqlusername
MYSQL_PASSWORD=password
MYSQL_DATABASE=sqldatabasename
SITE_DIR=/home/admin/blabla
BACKUP_DIR=/home/admin/backup/
BACKUP_NAME=yoursite-$(date +%Y%m%d-%H%M)
TMP_DIR=/home/admin/backup/$BACKUP_NAME
DB_BACKUP=yourwebsite-db.sql

mkdir --parents "$TMP_DIR" || { echo "ERROR: Could not create temp directory"; exit 1; }
cd "$TMP_DIR" || { echo "ERROR: Could not create temp directory"; exit 1; }
mysqldump -u $MYSQL_USERNAME --password=$MYSQL_PASSWORD $MYSQL_DATABASE > "$DB_BACKUP" || { echo "ERROR: Could not backup mysql db"; exit 1; }
mkdir site || { echo "ERROR: Could not create temp site directory"; exit 1; }
cp -R "$SITE_DIR" site || { echo "ERROR: Could not backup web site"; exit 1; }
tar czf "$BACKUP_DIR$BACKUP_NAME.tar.gz" * || { echo "ERROR: Could not create backup archive"; exit 1; }
rm -rf "$TMP_DIR" || { echo "ERROR: Could not clean up temp directory";  }
you can copy paste finished script in ssh, in the way that you wll normally select text in notepad, CTRL+C, and to paste it to ssh, press right mouse button.

Now we need to save it.

Press ESC on your keyboard.
Type:

Code: 
:write
and hit enter
now we need to exit from here
Code: 
:quit
and hit enter


Now we prepared a script that will backup our website, together with complete SQL database.

We need to make it more automatic

We want CRON job to run it at certain point of time, to make a backup, for example, when our site is least busy (which we previously investigated, when our website have least visitors)

to make it run on cron, type:

Code: 
crontab -e
and again text editor will open up, then press INSERT
If there is something already, leave it there, just add your line:

Code: 
15 3 * * * /home/scripts/blabla.script

This option will run our backup script at 3:15 AM server time, every day

To see more options, how to setup cron, with your own preferences, check here:

Code: 
http://adminschoice.com/crontab-quick-reference
Part 2 - Auto-download backup to windows based system

Ok, now we have this semi-automated...having backup on server where website is, isn't much helpful, in case when sky is falling on you.
So, now what we need is program named WinSCP, which can be downloaded here:

Code: 
http://winscp.net/eng/download.php
Download Installation package, and install it.

Open WinSCP, so you can enter your FTP (sFTP) details, and save them:



Save a session as something like root@mywebsite

Login to your ftp, just to see that you typed all properly.

You can close WinSCP now.

For example, in your C: drive, create folder named websitebackup to get C:\websitebackup <--this is where we will store our website backup (dooh)

By default, WinSCP is installed in "C:\Program Files (x86)\WinSCP\"

Move in that folder, and create a text file, named backup.txt

Right click mouse in that folder, you will get popup menu, go to New, then to Text Document



Open your newly created text file and copy paste, and change if necessary:

Code: 
option batch on
option confirm off
open root@mywebsite  // change this, in case you named your login profile in something different
cd /home/admin/backup  //also change this, in case this is not your backup folder on your web server
get -delete * "c:\websitebackup\"
exit
Save your backup.txt file in your WinSCP folder

We are almost done, just to automate windows to collect our backup now.

Go to Start > All Programs > Administrative Tools > Task Sheduler



On Right menu, click on Create Basic task

New window will pop up, name it, and give it some description:

Name: WinSCP
Description: downloading backup

Click Next, and you are in new menu, since we are creating new backup each day, it would be a good idea to synchronize webserver with backup, so, go with Daily option in menu, and hit Next

Define a proper time ( take care of timezones on both servers, if you 've put crontab to run on 3:15 on webserver, make a backup 10 minutes later, adding time 3:25)

Hit Next

Leave Action on default, as Start a program

Next again

Add full path to your WinSCP executable file, for example:

"C:\Program Files (x86)\WinSCP\WinSCP.exe"

In argument field, add this piece:

/console /script=backup.txt

And in field Start in:

C:\Program Files (x86)\WinSCP\

Hit Finish (or next)

Part 3 - We're done!

And, sha-zaaam, at 3:15, your webserver will make a full backup of your wordpress blog, and at 3:25, your windows server (home PC), will start downloading your backup trough FTP (only in case power is turned on )

So, here you go...enjoy

Magic of automation
cvrle77 Reviewed by cvrle77 on . Fully automated backup - SSH to Windows FTP Introduction: What we need, to make this thing working is: root access via ssh, to our web server, where our site(s) is(are) - for this, we can use putty, for example. Windows based system (another server or home PC) Windows 2008, 2003, or windows XP/7/Vista WinSCP (download link provided in manual) We also need a basic knowledge about ssh and of course, to install a simple program like WinSCP Rating: 5