Skip to content
/ barkup Public
  • Notifications You must be signed in to change notification settings
  • Fork 55
  • Star 215

A library for writing backup programs in Golang

215 stars 55 forks Branches Tags Activity
Star
Notifications You must be signed in to change notification settings

keighl/barkup

Branches Tags

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
.editorconfig
.editorconfig
 
 
.gitignore
.gitignore
 
 
.travis.yml
.travis.yml
 
 
CHANGELOG.md
CHANGELOG.md
 
 
README.md
README.md
 
 
barkup.coverprofile
barkup.coverprofile
 
 
barkup.go
barkup.go
 
 
barkup_test.go
barkup_test.go
 
 
doc.go
doc.go
 
 
mysql.go
mysql.go
 
 
mysql_test.go
mysql_test.go
 
 
postgres.go
postgres.go
 
 
postgres_test.go
postgres_test.go
 
 
rethinkdb.go
rethinkdb.go
 
 
rethinkdb_test.go
rethinkdb_test.go
 
 
s3.go
s3.go
 
 
s3_test.go
s3_test.go
 
 

Repository files navigation

Barkup

Build Status Coverage Status

godoc.org/github.com/keighl/barkup

Barkup is a library for backing things up. It provides tools for writing bare-bones backup programs in Go. The library is broken out into exporters and storers. Currently, those are:

Exporters: MySQL Postgres RethinkDB

Storers: S3

Quick Example (mysql to s3)

Here's a go program that backups up a MySQL database (Exporter) to an S3 bucket (Storer) using barkup. The resulting executable is plopped on a server somewhere and scheduled to execute via CRON.

package main

import "github.com/keighl/barkup"

func main() {

    // Configure a MySQL exporter
    mysql := &barkup.MySQL{
        Host:     "localhost",
        Port:     "3306",
        DB:       "production_db",
        User:     "root",
        Password: "cheese",
    }

    // Configure a S3 storer
    s3 := &barkup.S3{
        Region:       "us-east-1",
        Bucket:       "backups",
        AccessKey:    "*************",
        ClientSecret: "**********************",
    }

    // Export the database, and send it to the
    // bucket in the `db_backups` folder
    err := mysql.Export().To("db_backups/", s3)
    if err != nil {
        panic(err)
    }
}
$ go build
@hourly /path/to/backup-program

Cron

Because barkup executes system commands like tar, mysqldump, etc, you may run into issues where crontab can't find 'em. The crontab shell is super stripped down, but you can shim the PATH environment variable to access stuff.

PATH=$PATH:/usr/local/bin:/usr/bin:/bin

@hourly /path/to/backup-program

This is especially the case for the RethinkDB exporter rethink-dump which executes system commands itself ("exec inception").


Exporters

Exporters provide a common interface for backing things up via the Export() method. It writes an export file to the local disk, and returns an ExportResult which can be passed on to a storer, or to another location on the disk.

// Exporter
mysql := &barkup.MySQL{...}

// Export Result
result := mysql.Export()
if (result.Error != nil) { panic(result.Error) }

// Send it to a directory path on a storer
err := result.To("backups/", storer)

// OR just move it somewhere on the local disk
err := result.To("~/backups/", nil)

MySQL

The mysql exporter uses mysqldump to pump out a gzipped archive of your database. mysqldump must be installed on your system (it probably is if you're using mysql), and accessible to the user running the final program (again, it probabaly is).

Usage

mysql := &barkup.MySQL{
  Host: "127.0.0.1",
  Port: "3306",
  DB: "XXXXX",
  User: "XXXXX",
  Password: "XXXXX",
  // Any extra mysqldump options
  Options: []string{"--skip-extended-insert"}
}

// Writes a file `./bu_DBNAME_TIMESTAMP.sql.tar.gz`
result := mysql.Export()

if (result.Error != nil) { panic(result.Error) }

Postgres

The postgres exporter uses pg_dump to make a gzipped archive of your database. pg_dump must be installed on your system (it probably is if you're using postgres).

Usage

postgres := &barkup.Postgres{
  Host: "127.0.0.1",
  Port: "5432",
  DB: "XXXXXXXX",

  // Not necessary if the program runs as an authorized pg user/role
  Username: "XXXXXXXX",

  // Any extra pg_dump options
  Options: []string{"--no-owner"},
}

// Writes a file `./bu_DBNAME_TIMESTAMP.sql.tar.gz`
result := postgres.Export()

if (result.Error != nil) { panic(result.Error) }

Connection credentials

You have two options for allowing barkup to connect to your DB.

Add a ~/.pgpass for account that will run the backup program.

Or, run the backup program from an authenticated user, like postgres:

$ sudo -i -u postgres
$ ./backup-program

RethinkDB

The RethinkDB exporter uses rethinkdb dump to make a gzipped archive of your cluster. rethinkdb-dump must be installed on your system.

$ sudo pip install rethinkdb

Usage

rethink := &barkup.RethinkDB{
  Name: "nightly",
  Connection: "0.0.0.0:28015",
  // You can specify specific databases and/or tables to dump (by default it dumps your whole cluster)
  Targets: []string{"site", "leads.contacts"},
}

// Writes a file `./bu_nightly_TIMESTAMP.tar.gz`
result := rethink.Export()
if (result.Error != nil) { panic(result.Error) }

Storers

Storers take an ExportResult object and provide a common interface for moving a backup to someplace safe.

// For chaining an ExportRestult
err := someExportResult.To("backups/", someStorer)

// OR
err := someStorer.Store(someExportResult, "backups/")

S3

The S3 storer puts the exported file into a bucket at a specified directory. Note, you shouldn't use your global AWS credentials for this. Instead, create bucket specific credentials via IAM.

Usage

s3 := &barkup.S3{
  Region: "us-east-1",
  Bucket: "backups",
  AccessKey: "XXXXXXXXXXXXX",
  ClientSecret: "XXXXXXXXXXXXXXXXXXXXX",
}

err := someExportResult.To("data/", s3)

Region IDs

  • us-east-1
  • us-west-1
  • us-west-2
  • eu-west-1
  • ap-southeast-1
  • ap-southeast-2
  • ap-northeast-1
  • sa-east-1

About

A library for writing backup programs in Golang

Resources

Readme
Activity

Stars

215 stars

Watchers

10 watching

Forks

55 forks
Report repository

Releases

4 tags

Packages

No packages published

Contributors 2

  •  
  •  

Languages

  • Go 100.0%

Footer

© 2024 GitHub, Inc.

玻璃钢生产厂家四川水果玻璃钢雕塑销售厂家漳州商场美陈玻璃钢地藏王雕塑图片徐汇玻璃钢雕塑商场柜台美陈布置玻璃钢孔子雕塑生产厂商户外商场美陈哪里买徐州玻璃钢雕塑景观设计love玻璃钢雕塑綦江玻璃钢人物雕塑商场装饰玻璃钢卡通雕塑电话多少园林玻璃钢人物雕塑批发西陵玻璃钢花盆花器铜玻璃钢花盆彭州玻璃钢动物雕塑淮北个性化玻璃钢雕塑销售电话大型商场美陈定制自发光动物玻璃钢雕塑厂家电话怀集玻璃钢动物雕塑批发广州公园玻璃钢雕塑东莞玻璃钢花盆报价南通圣诞商场美陈抚州户外玻璃钢雕塑哪家便宜黑龙江公园玻璃钢雕塑供应商泡沫雕塑翻制玻璃钢磨具佛山发光景观玻璃钢雕塑制作南京抽象玻璃钢雕塑市场泡沫雕塑怎么翻玻璃钢西安玻璃钢动物雕塑价格玻璃钢雕塑制作合同香港通过《维护国家安全条例》两大学生合买彩票中奖一人不认账让美丽中国“从细节出发”19岁小伙救下5人后溺亡 多方发声单亲妈妈陷入热恋 14岁儿子报警汪小菲曝离婚始末遭遇山火的松茸之乡雅江山火三名扑火人员牺牲系谣言何赛飞追着代拍打萧美琴窜访捷克 外交部回应卫健委通报少年有偿捐血浆16次猝死手机成瘾是影响睡眠质量重要因素高校汽车撞人致3死16伤 司机系学生315晚会后胖东来又人满为患了小米汽车超级工厂正式揭幕中国拥有亿元资产的家庭达13.3万户周杰伦一审败诉网易男孩8年未见母亲被告知被遗忘许家印被限制高消费饲养员用铁锨驱打大熊猫被辞退男子被猫抓伤后确诊“猫抓病”特朗普无法缴纳4.54亿美元罚金倪萍分享减重40斤方法联合利华开始重组张家界的山上“长”满了韩国人?张立群任西安交通大学校长杨倩无缘巴黎奥运“重生之我在北大当嫡校长”黑马情侣提车了专访95后高颜值猪保姆考生莫言也上北大硕士复试名单了网友洛杉矶偶遇贾玲专家建议不必谈骨泥色变沉迷短剧的人就像掉进了杀猪盘奥巴马现身唐宁街 黑色着装引猜测七年后宇文玥被薅头发捞上岸事业单位女子向同事水杯投不明物质凯特王妃现身!外出购物视频曝光河南驻马店通报西平中学跳楼事件王树国卸任西安交大校长 师生送别恒大被罚41.75亿到底怎么缴男子被流浪猫绊倒 投喂者赔24万房客欠租失踪 房东直发愁西双版纳热带植物园回应蜉蝣大爆发钱人豪晒法院裁定实锤抄袭外国人感慨凌晨的中国很安全胖东来员工每周单休无小长假白宫:哈马斯三号人物被杀测试车高速逃费 小米:已补缴老人退休金被冒领16年 金额超20万

玻璃钢生产厂家 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化