How to Setup Automated Backups with BTSync

by Valkryst

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 of BTSync to use on your home computer and download this very specific version 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.

If you wish to learn how to backup your server databases, please refer to this tutorial.

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

        # 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.

          "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/",

          "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" : "",
            "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" :

        // 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'll 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.

        # 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.

        # 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. The line with "!/bin/bash" is
        # a part of the script and it does need to have the "#" symbol before it.
        ./btsync --config sync.conf

        # Enter the following to begin editing the second script.

        # 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.
        pkill btsync

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

        # To start BTSync just enter the BTSync directory and type...

        # To stop BTSync just enter the BTSync directory and type...

You can now log into BTSync by either going to or myServerIP:8888 in any web browser. You can log in with the btsync username and password.

Tips & Tricks: