Send backup to Dropbox

Send LogicMachine backup file to Dropbox #

Create a Dropbox app #

  1. Go to https://www.dropbox.com/developers/apps and click Create app.

  2. Fill in the form as click Create app:

  • Choose an API = Scoped access
  • Choose the type of access you need = App folder
  • Choose a unique name for your app, a folder with the same name will be created in your Dropbox account inside of the Apps folder.

dropbox step 1

  1. Switch to Permissions tab, enable files.content.write permission and click Submit at the bottom of the window.

dropbox step 2

  1. Switch to Settings, scroll down to Generated access token and click Generate. Copy the token and paste it into the script, replacing ... with the actual token.

dropbox step 3

Scheduled script #

Create a scheduled script that runs the backup procedure. Copy/paste the code and replace the token. Run the script and check the results in the Logs tab.

filepath can contain folders (separated by /). This can be useful if you want to use a single app for backups from multiple LMs.

token = '...'

filepath = '/LM-' .. os.date('%Y-%m-%d') .. '.zip'

json = require('json')
ltn12 = require('ltn12')
http = require('socket.http')

webrequest = require('webrequest')
filedata, err = webrequest('general', 'backup')

res, code, hdrs, status = http.request({
  url = 'https://content.dropboxapi.com/2/files/upload',
  method = 'POST',
  headers = {
    ['Authorization'] = 'Bearer ' .. token,
    ['Content-Type'] = 'application/octet-stream',
    ['Content-Length'] = #filedata,
    ['Dropbox-API-Arg'] = json.encode({
      path = filepath,
      mode = 'add',
      autorename = true,
      mute = false
    }),
  },
  source = ltn12.source.string(filedata),
})

if code == 200 then
  log('dropbox backup ok')
else
  log('dropbox backup failed', res, code, hdrs, status)
end