Contact SalesSitemapCustomer Login

Automate Backup Retrieval with WinSCP

WinSCP offers Windows users with access to a Linux VPS the option to store local backups - paired with a simple WinSCP script and the Windows Scheduler service, WinSCP becomes a very effective tool for the regular backup of selected files with a minimal amount of bandwidth usage.


Contents

[edit]

Prepare for Automated Backups

  1. Create a directory on your local machine to store your backup files
  2. Create a "backup" user with limited privileges (the backup user's password will be stored in clear text on your local machine)
  3. Prepare a cron job which creates and compresses an archive of the files you wish to back up - the cron job should store the archive in your backup user's home directory


[edit]

Create a WinSCP Backup Script

  1. Copy the script below into an empty .txt file
  2. Replace the following variables with your information:
    • YOUR_IP_ADDRESS - An IP address allocated to your VPS
    • YOUR_BACKUP_USERNAME - The username which you selected for your backup user account
    • YOUR_BACKUP_PASSWORD - The password for your backup user account
    • YOUR_BACKUP_FILENAME - The remote file name for your backup archive
    • YOUR_LOCAL_BACKUP_FOLDER - The full path to your local backup folder (e.g. C:\backups\)


# VPSLink Sample Backup Script for WinSCP

# Comment out the next two lines to test
option batch on
option confirm off

# Connect - format: user:password@host
open YOUR_BACKUP_USERNAME:YOUR_BACKUP_PASSWORD@YOUR_IP_ADDRESS

# Change remote directory
cd /home/YOUR_BACKUP_USERNAME

# Force binary mode transfer
option transfer binary

# Download backup file to the local directory
get YOUR_BACKUP_FILENAME YOUR_LOCAL_BACKUP_FOLDER

# Disconnect
close

# Exit WinSCP
exit


[edit]

Test WinSCP Backup Script

You must run your WinSCP backup script interactively at least one time under the Windows user account which you will use for automation to accept your virtual private server's host key.

  1. Comment out the following lines in your backup script:
    option batch on
    option confirm off
  2. Create a copy of your backup file on your VPS for testing purposes
  3. Run the WinSCP script from the Windows command line
    1. Go to the Start button
    2. Select Run...
    3. Enter cmd and click OK
    4. Enter "C:\Program Files\WinSCP\winscp.exe" /console /script=YOUR_SCRIPT_FILENAME (where YOUR_SCRIPT_FILENAME is the path to your script with a default WinSCP installation)
    5. When prompted, enter Y to accept your virtual private server's host key (the key will be stored with your Windows user profile for future use - you will not be prompted to accept the key again)
  4. Confirm that your test backup file was downloaded to the correct location
  5. Uncomment the following lines in your backup script:
    # option batch on
    # option confirm off


[edit]

Automate WinSCP Backups with Windows Scheduler

  1. Go to the Start button
  2. Select Settings > Control Panel
  3. Select Scheduled Tasks to open the Scheduled Task Wizard
  4. Select Add Scheduled Task and click Next
  5. Locate and select WinSCP on the program list and click Next
  6. Enter a name for the task, select the task frequency, and then click Next
  7. Enter and confirm your Windows user account password for the task's RunAs credentials and click Next
  8. Check the Open advanced properties for this task when I click Finish box
  9. Click Finish to exit the Scheduled Task Wizard and open the task's properties dialog
  10. Add /console /script=YOUR_SCRIPT_FILENAME (where YOUR_SCRIPT_FILENAME is the path to your script) after the WinSCP program path in the Run field
  11. Click Apply and confirm your Windows user account password if prompted
  12. Click OK to exit the task's properties dialog
  13. From the Scheduled Tasks window, right-click on your WinSCP backup task and select Run to test the new task

Your WinSCP backup task will now run automatically at the frequency which you specified if your Windows machine is powered on and your VPS is available.


[edit]

Related Links

Retrieved from "http://wiki.vpslink.com/Automate_Backup_Retrieval_with_WinSCP"
Recent Changes | RSS RSS Feed