backup

package module
v0.0.0-...-ba2cf89 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 2, 2019 License: MIT Imports: 9 Imported by: 0

README

sftp-s3-backup

A simple utility to backup the files on sftp to s3

Usage:

It exposes a simple utility to backup the files onto S3 from the sftp. The usage pattern is as follows:

package main

import (
  "log",
  backup "github.com/babbarshaer/sftp-s3-backup"
)

func main() {

  config := backup.Config{
    User:              "user",
    Address:           "address",
    Port:              22,
    PublicKeyLocation: "/home/user/.ssh/id_rsa.pub",
  }

  client := backup.Client(config)
  err := client.Init()
  if err != nil {
    log.Fatalf("Unable to initialize the client: %s", err.Error())
  }

  defer client.Close()

  err = client.Backup(
    "/data/user/uploads",
    "aws.bucket",
    backup.DefaultPathTransformer)

  // If we don't want the default path transformer
  // we can override it with our own implementation.

  if err != nil {
    log.Fatalf("Unable to backup, err: %s", err.Error())
  }
}
AWS Variables

In order to backup the files onto S3, we need to access the AWS variables which would allow us to login to the platform and upload the information into corresponding bucket. More information could be read at AWS Env

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultS3PathTransformer = func(path string) string {
	return path
}

Functions

func Upload

func Upload(bucket string, key string, body io.Reader) error

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(config Config) *Client

func (*Client) Backup

func (c *Client) Backup(directory, bucket string, transformer S3PathTransform) error

Backup simply backsup all the files present in the directory to the mentioned bucket in S3. It also applies path transformer to each fileentry when identifying the key under which it needs to be uploaded onto s3.

func (*Client) Close

func (c *Client) Close() error

func (*Client) Init

func (c *Client) Init() error

Init bootstraps the backup client with the necessary data and connections to perform the task of backing up data from the sftp.

type Config

type Config struct {
	User              string
	Address           string
	Port              int
	PublicKeyLocation string
}

type S3PathTransform

type S3PathTransform = func(sftpPath string) string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL