Code Monkey home page Code Monkey logo

etcd-backup's Introduction

etcd-backup

A simple shell script for backing up etcd v2 and v3 datastores

References

https://coreos.com/etcd/docs/latest/op-guide/recovery.html

Requirements

This script requires systemd-cat to write log entries to the journal.

  • CentOS 7+ (tested, working)
  • Ubuntu 15.04+ (not tested, should work)

Useage

This script is expected to run on the server that runs etcd. Take note of installations using cert based authentication, this will effect the way the endpoints are referenced. Since this is expected to run locally on each etcd member in the cluster, the script defaults to ENDPOINTS=https://localhost:2379

Take note of the default data location (ETCD_DATA_DIR) and backup location (ETCD_BACKUP_PREFIX). These can be change by modifying the variables at the top of the shell script.

In order to run this script, you must set an etcd API version and an interval. This can be done with the following options:

 --etcdv2         Sets etcd backup version to etcdv2 API. This is required if you have mixed v2/v3 data.

 --etcdv3         Sets etcd backup version to etcdv3 API. This will not include v2 data.

 --hourly         Sets the backup location to the hourly directory.

 --daily          Sets the backup location to the daily directory.

Kubernetes 1.6+ uses etcd v3 by default, however some plugins may use etcd v2. In this case, we're required to use the etcd v2 backup function since it will contain both v2 and v3 data.

Installation

  1. Place etcd_backup.sh script in /opt/scripts/
  2. Create crontab entry for root
# Hourly etcd backups
0 * * * * sh /opt/scripts/etcd_backup.sh --etcdv3 --hourly
# Daily etcd backups
0 0 * * * sh /opt/scripts/etcd_backup.sh --etcdv3 --daily
# Keep last 6 hourly etcd backups, delete the rest
5 * * * * cd /var/lib/etcd/backups/hourly/; ls -tp | tail -n +7 | xargs -d '\n' -r rm -r --
# Keep last 7 daily etcd backups, delete the rest
5 * * * * cd /var/lib/etcd/backups/daily/; ls -tp | tail -n +8 | xargs -d '\n' -r rm -r --

Logging

This script will write to the journal on systemd servers. You can see this by filtering the journal for the specific identifier:

$ journalctl -t etcd_backup
-- Logs begin at Wed 2018-02-14 18:15:06 CST, end at Tue 2018-02-27 10:10:38 CST. --
Feb 27 10:02:29 test-kube-master1.lucid.local etcd_backup[92811]: etcdv2 backup completed successfully.

TODO

Change log

0.1.0

  • Initial commit
  • Licensed

etcd-backup's People

Contributors

nickkeyzer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.