[Tutorial] Use WinSCP to backup your database files automatically.

Hello there!
I've recently had the urge to backup my game files from my host (streamline-servers) on my hard drive via FTP, but automate it every 5 hours since the game's backups only last about that long. Unfortunately, the FTP I just learned to use, FileZilla, doesn't allow automation so I learned to use WinSCP (which supports Windows PowerShell ).
  So what does this do? Every "x" hours you can fetch every database file from your game server (assuming you aren't hosting the machine) via FTP and save it to your hard drive in a dated folder while your computer is on so you have a back up should something go wrong while you're asleep, etc (outside of that 5 hour backup window).
1. Download and install WinSCP.
2. Create a backup folder where backups will be placed (i.e. D:DesktopConan)
3. Create a file in your WinSCP directory or newly created backup folder with any name, but must have the Windows PowerShell extension ".ps1"
4. Copy and paste the following code into your .ps1 file via text editor:

Now that you've copy / pasted this code into your .ps1 file, you'll need to adjust some things.

  • On Line 4, replace "PathToWinSCP" with the folder location in which you installed WinSCP (i.e. E:WinSCPWinSCPnet.dll) – Don't forget the double
  • On Line 9, replace "YourServerIP" with your server's IP address
  • On Line 10, replace "ServerPort" with your server's FTP port #
  • On Line 11, replace "YourUserName" with the username required to log into your FTP server
  • On Line 12, replace "YourUserPassword" with your required password for the FTP server
  • On Line 22, replace "YourServerIP" & "ServerPort" so it matches your IP address and port with the correct format of "$remotePath = "/"
  • On Line 23, replace "LocationToYourBackupFolder" with the path to the folder we made on step #2
  • On Line 24, replace "LocationToYourBackupFolder" with the path to the folder we made on step #2

Now that we've got that all done, save your .ps1 file and you're now ready to schedule windows to run this PowerShell Command when you'd like. To do so, simply do the following:

  1. Open Task Scheduler (%windir%system32taskschd.msc) and click "Create Task" on the right side.
  2. Name the task something you'll remember then select your security options (if you want it to run when you're logged in or not).
  3. Click the "triggers" tab (this is where we set when and how often the task will run). Click "New" then select "daily" and on the bottom half select "repeat task every" and in the box type in "4 hours". Change the "duration" box to indefinitely. Make sure "Enabled" is checked.
  4. Select the "actions" tab and click "New". On the drop down select "start a program". In the program/script box type in "Powershell.exe" or type in the path to powershell for your system version – 64x is C:WindowsSystem32WindowsPowerShellv1.0powershell.exe. In the "add arguments" box type in "-ExecutionPolicy Bypass -Windowstyle Hidden" followed by the path to your .ps1 file for example: "-ExecutionPolicy Bypass -Windowstyle Hidden E:WinSCPBackup.ps1" (Note: -Windowstyle Hidden is optional).
  5. Select the "conditions" tab. You can specify if you want your backup to occur when on AC power or battery her~~~~e and if your computer will wake up to run this task – all things are optional here to your preference.
  6. Select the "settings" tab. These settings are again optional, but you can schedule it to run as soon as possible incase you shut down the computer and miss a backup.
  7. Click OK and then select your task in the list of shown tasks. Right click the task and select "Run". You should now see a newly created folder in your backup folder with a list of all of your game.db files being generated.  
    It should be noted that I'm a complete novice at all of this and just figured out how to do this for myself. If you have any troubles I might not be able to help ya!

Congratulations, this is the end.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.