Categorygithub.com/xacnio/backupper
module
0.0.9
Repository: https://github.com/xacnio/backupper.git
Documentation: pkg.go.dev

# README

(IN DEVELOPMENT)

Backupper

The tool is for backuping file from FTP/SFTP source and save it another FTP/SFTP backup destination.

Features

  • Schedule backuping with CRON expression in config file
  • Download files from FTP/SFTP sources
  • Executing commands on source server (SFTP only)
  • Upload files to FTP/SFTP destinations
  • Upload files to Telegram with Bot API (max 50 MB files)
  • Limit the file count in target folder (if limit is reached, oldest backups will be deleted)
  • Limit the total file size in target folder (if limit is reached, oldest backups will be deleted)
  • Limit the target folder by duration (oldest backups than date will be deleted)

Config

Main config file is config.json in the root folder of the project. Also you can use config.example.json as a template.

Main Structure

{
  "timezone": "Europe/Istanbul",
  "dateFormat": "2006-01-02__15-04-05",
  "backups": []
}
KeyDescriptionType
timezoneTZ identifierstring
dateFormatthe format of the date to be added to the file name (Golang time format)string
logLevelLog level (debug, info, warn, error, dpanic, panic, fatal)string
backupsBackup schedulesarray

Backup Schedule Structure

{
  "name": "backup-title",
  "cronExpr": "*/60 * * * * *",
  "callbackUrl": "http://example.com/callback",
  "deleteLocal": true,
  "source": {
    "type": "sftp",
    "info": {
      "host": "127.0.0.1",
      "port": 22,
      "user": "root",
      "pass": "",
      "privateKeyFile": "~/.ssh/custom_id_rsa",
      "privateKeyPass": "",
      "variables": {
        "foo": "bar",
        "bar": 123,
        "baz": true
      },
      "beforeCommands": [
        "echo $foo > /tmp/backupper/$BACKUP_ID/foo.txt",
        "echo $bar > /tmp/backupper/$BACKUP_ID/bar.txt",
        "echo $baz > /tmp/backupper/$BACKUP_ID/baz.txt",
        "cd /opt/foo/bar",
        "zip -r /tmp/backupper/$BACKUP_ID/foo_backup.zip ."
      ],
      "downloads": [
        "foo_backup.zip",
        "foo.txt",
        "bar.txt",
        "baz.txt"
      ],
      "afterCommands": [
        "rm -rf /tmp/backupper/$BACKUP_ID/"
      ]
    }
  },
  "destination": {
    "type": "ftp",
    "deleteAfterUpload": true,
    "info": {
      "host": "backup-ftp.example.com",
      "port": 21,
      "user": "root",
      "pass": "p4ssw0rd",
      "target": "/up/backups/foo/",
      "limitByCount": 3,
      "LimitBySize": 1073741824,
      "limitByDate": "2 DAYS"
    }
  }
}
KeyDescriptionType
nameName of the backup schedulestring
cronExprCRON expression (also supports cronSeconds)string
callbackUrlCallback URL to be called after backup process is completedstring
deleteLocalDelete local files after upload process is completedbool
sourceSource server informationobject
destinationDestination server informationobject

Source

KeyDescriptionType
typeSource server type (ftp/sftp)string
infoSource server informationobject

Source Info (FTP)

KeyDescriptionType
hostFTP server hoststring
portFTP server portint
userFTP server usernamestring
passFTP server passwordstring
downloadsFiles to be downloaded from FTP server (only files, not directories)array

Source Info (SFTP)

KeyDescriptionType
hostSFPT server hoststring
portSFTP server portint
userSFTP server usernamestring
passSFTP server passwordstring
privateKeyFilePrivate key file pathstring
passphrasePrivate key passphrasestring
variablesCustom variables to be used in SSH commandsobject
beforeCommandsSSH Commands to be executed before download processarray
downloadsFiles to be downloaded from SFTP server (only files, not directories)array
afterCommandsSSH Commands to be executed after download processarray

SFTP - SSH Command Variables

VariableDescriptionType
$BACKUP_IDUnique ID of the backup process (generated by the tool) (Nano unix timestamp)string
$BACKUP_NAMEName of the backup schedulestring

Destination

KeyDescriptionType
typeDestination server type (ftp/sftp/telegram_bot)string
deleteAfterUploadDelete files after upload process is completedbool
infoDestination server informationobject

Destination Info (Telegram with Bot API) (max 50 MB files)

KeyDescriptionType
tokenTelegram bot token from @BotFatherstring
chatIDTelegram chat ID (channel/group) or public usernamestring

Destination Info (FTP)

KeyDescriptionType
hostFTP server hoststring
portFTP server portint
userFTP server usernamestring
passFTP server passwordstring
targetTarget folder on FTP serverstring
limitByCountLimit the file count in target folderint
limitBySizeLimit the total file size in target folder (bytes)int
limitByDateLimit the target folder by duration (duration format)string

Destination Info (SFTP)

KeyDescriptionType
hostSFTP server hoststring
portSFTP server portint
userSFTP server usernamestring
passSFTP server passwordstring
privateKeyFilePrivate key file pathstring
passphrasePrivate key passphrasestring
targetTarget folder on SFTP serverstring
limitByCountLimit the file count in target folderint
limitBySizeLimit the total file size in target folder (bytes)int
limitByDateLimit the target folder by duration (duration format)string

limitByDate - Duration Format

FormatDate Range
5 MINUTESAll files before 5 minutes
1 HOURAll files before 1 hour
2 DAYSAll files before 2 days
3 WEEKSAll files before 3 weeks
4 MONTHSAll files before 4 months
5 YEARSAll files before 5 years

Multiple durations can be used together. (e.g. 1 HOUR 30 MINUTES)

Callback Post Data

{
  "backup_date": "2023-07-20T15:27:50+03:00",
  "backup_destination": "sftp",
  "backup_destination_result": {
    "totalUploadedFiles": 1,
    "totalUploadedSize": 5820073
  },
  "backup_duration": "19.7989235s",
  "backup_id": "1689856070674044500",
  "backup_name": "test-backup",
  "backup_source": "sftp",
  "backup_ts": 1689856070
}
KeyDescriptionType
backup_dateBackup date (RFC3339)string
backup_destinationDestination server type (ftp/sftp)string
backup_destination_resultDestination server upload resultobject
backup_durationBackup duration (time.Duration string)string
backup_idUnique ID of the backup process (generated by the tool) (Nano unix timestamp)int
backup_nameName of the backup schedulestring
backup_sourceSource server type (ftp/sftp)string
backup_tsBackup timestamp (Unix seconds)int

Used Modules

# Packages

No description provided by the author
No description provided by the author