This is a read only copy without any forum functionality of the old Modcraft forum.
If there is anything that you would like to have removed, message me on Discord via Kaev#5208.
Big thanks to Alastor for making this copy!

Menu

Author Topic: [Linux] How to Setup Automated Backups with BTSync  (Read 1590 times)

Valkryst

  • Moderators
  • Model Change Addict
  • *****
  • Posts: 224
    • View Profile
    • http://valkryst.com/blog/
[Linux] How to Setup Automated Backups with BTSync
« 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 of BTSync to use on your home computer from here 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 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.

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

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:

  • device_name - You can put whatever you want here. I usually just enter something similar to Valkryst's Server.
  • check_for_updates - Set this to false because, if you update, a lot of things can go wrong and most of this setup is known to break.
  • login - Set this to btsync.
  • password - Set this to whatever password you gave the btsync account.
  • secret - Set this to whatever the generated secret key you received earlier is.
  • dir - Set this to /home/btsync_home/.

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:


  • When backing up a file or directory, you will need to give the BTSync account ownership or shared ownership through a user group of the file or folder.
  • On your home computer you can set BTSync to save all received files for a specific folder into your Dropbox or Google Drive folders. This will ensure that your data always has a tertiary backup with a trusted host encase of backup. Although I would recommend running a script that compresses and encrypts your data if you do this just encase.
  • On your server you can set Google Drive or Dropbox to use the same folder, and maybe folders, as BTSync to the same effect as the previous point.
  • In many cases, where storage is limited, you will want to remove all revision backups that BTSync automatically keeps. To do this, just log into the web interface, go into the Property Options for whichever folder you want to edit, and deselect Store deleted files in SyncArchive.
  • To add a folder on the web interface, select Add Folder, click the Generate Secret button, then select the folder, and click the Add button. Please remember that BTSync cannot access folders that it doesn't have permission to.
  • To get the keys used to share a folder on the server with any other running BTSync program, go onto the web interface, select the Sharing Options for whichever folder you want, and then just select whichever key and option you want.
« Last Edit: January 01, 1970, 01:00:00 am by Admin »
MY BLOG IS NOW HERE.