Modcraft - The community dedicated to quality WoW modding!

Wrath of the Lich King Modding => Miscellaneous => Tutorials => Topic started by: Valkryst on April 27, 2015, 02:14:26 am

Title: [Linux] How to Setup Automated Backups with BTSync
Post by: Valkryst on April 27, 2015, 02:14:26 am
Before I type the rest, I will admit that I'm far from an expert on Linux or bash. I did a lot of googling and had a bit of help from a friend of mine to figure out how to use BTSync and set it up properly.

Before you continue reading, please download a current version (https://www.getsync.com/#compare-chart) of BTSync to use on your home computer from here and download this very specific version (https://mega.co.nz/#!mUN0iYzJ!N_H5Vs5ZJSIYiItXH1wOdJV9QuMlmBfQp_IKz3t7TQ4) to use on your server. The rest of this post will explain how to set up BTSync on your server and a few tips on using it as well as situations where it can be used. If you wish to learn how to backup your server databases, please refer to this tutorial (http://valkryst.com/blog/?p=75).

--------------------------------------------------------------------------

For those of you who know a bit about Linux, you can just skim most of this tutorial and alter the setup steps to fit your needs. For everyone else, just log into your server using PuTTY or a similar program and just copy the commands into the terminal as you see them.

Code: [Select]
# The following commands create a new user and let you choose the password for
# the account. You will be able to log into this user through PuTTY just as you
# do with your root account, but it won't be able to do as much as the root
# account can.
useradd btsync
passwd btsync

# The following commands create a new home directory for BTSync and set
# ownership of the folder and everything within it to the new btsync account.
cd /home/
mkdir btsync_home
chown -R btsync:btsync /home/btsync_home/
cd btsync_home/

# Now you will need to either use FileZilla or a similar program to transfer
# whichever copy of BTSync fits your Linux distribution into the new
# /home/btsync_home/ folder. Make sure that you've extracted everything.
# As a safe measure, just re-run the following command to ensure that btsync
# has ownership of all the new files.
chown -R btsync:btsync /home/btsync_home/

# Now log out of the root account and log into the btsync account using the
# username btsync and whatever password that you gave the account.

# After extracting the btsync files into /home/btsync_home/ run the following
# commands to generate a config file and secret key. You will need the secret
# key later on, so copy it down.
./btsync --dump-sample-config > sync.conf
./btsync --generate-secret
mkdir .sync

Now that the btsync user and basic setup are all done, you will need to edit the newly generated config file for btsync to run correctly. The config file can look pretty confusing, so I've provided a sample config along with notes on what to edit below.

Code: [Select]
{
  "device_name": "Valkryst's Server",
  "listening_port" : 0,                       // 0 - randomize port

/* storage_path dir contains auxilliary app files
   if no storage_path field: .sync dir created in the directory
   where binary is located.
   otherwise user-defined directory will be used
*/
  "storage_path" : "/home/btsync_home/.sync",

// uncomment next line if you want to set location of pid file
// "pid_file" : "/var/run/btsync/btsync.pid",


  "check_for_updates" : true,
  "use_upnp" : true,                              // use UPnP for port mapping


/* limits in kB/s
   0 - no limit
*/
  "download_limit" : 0,
  "upload_limit" : 0,

/* remove "listen" field to disable WebUI
   remove "login" and "password" fields to disable credentials check
*/
  "webui" :
  {
/* directory_root path defines where the WebUI Folder browser starts
   (linux only)
*/
// "directory_root" : "/home/user/MySharedFolders/",

    "listen" : "0.0.0.0:8888",
    "login" : "btsync",
    "password" : "btsyncAccountPassword"
  }

/* !!! if you set shared folders in config file WebUI will be DISABLED !!!
   shared directories specified in config file
   override the folders previously added from WebUI.
*/
/*
  ,
  "shared_folders" :
  [
    {
//  use --generate-secret in command line to create new secret
      "secret" : "ValkrystSecretKey",                   // * required field
      "dir" : "/home/btsync_home/", // * required field

//  use relay server when direct connection fails
      "use_relay_server" : true,
      "use_tracker" : true,
      "use_dht" : false,
      "search_lan" : true,
//  enable SyncArchive to store files deleted on remote devices
      "use_sync_trash" : true,
//  restore modified files to original version, ONLY for Read-Only folders
//    "overwrite_changes" : false,
//  specify hosts to attempt connection without additional search
      "known_hosts" :
      [
        "192.168.1.2:44444"
      ]
    }
  ]
*/

// Advanced preferences can be added to config file.
// Info is available in BitTorrent Sync User Guide.

}

In the config you'll need to edit the following fields:


Now that the config has been properly setup, you just need to create a start and stop script to start and stop BTSync. Whenever you alter the config in the future, the changes will not take affect until you restart BTSync.

Code: [Select]
# Install nano to edit the script with. You can use vim or another similar
# program if you wish.
sudo apt-get install nano -y

# Enter the directory for BTSync
cd /home/btsync_home/

# Enter the following to begin editing the first script.
nano Start.sh

# Type in the following two lines exactly as they appear and then press CTRL+X
# then press Y and then ENTER to save the file.
#!/bin/bash
./btsync --config sync.conf

# Enter the following to begin editing the second script.
nano Stop.sh

# Type in the following two lines exactly as they appear and then press CTRL+X
# then press Y and then ENTER to save the file.
#!/bin/bash
pkill btsync

# Now that both scripts have been made, enter the following commands to allow
# both scripts to be run.
chmod +x Start.sh
chmod +x Stop.sh

# To start BTSync just enter the BTSync directory and type...
./Start.sh

# To stop BTSync just enter the BTSync directory and type...
./Stop.sh
You can now log into BTSync by either going to www.example.com:8888 or myServerIP:8888 in any web browser. You can log in with the btsync username and password.

Tips & Tricks: