etcd2-backup.service 1.1 KB

1234567891011121314151617181920212223242526272829
  1. [Unit]
  2. Description=rclone powered etcd2 backup service
  3. After=etcd2.service
  4. [Service]
  5. Type=oneshot
  6. ExecStartPre=/usr/bin/rm -rf ${ETCD_BACKUP_DIR}
  7. ExecStartPre=/usr/bin/mkdir -p ${ETCD_BACKUP_DIR}/member/snap
  8. ExecStartPre=/usr/bin/echo ETCD_DATA_DIR: ${ETCD_DATA_DIR}
  9. ExecStartPre=/usr/bin/echo ETCD_BACKUP_DIR: ${ETCD_BACKUP_DIR}
  10. ExecStartPre=/usr/bin/etcdctl backup --data-dir=${ETCD_DATA_DIR} --backup-dir=${ETCD_BACKUP_DIR}
  11. ExecStartPre=/usr/bin/touch ${ETCD_BACKUP_DIR}/member/snap/iamhere.txt
  12. # Copy the last backup, in case the new upload gets corrupted
  13. ExecStartPre=-/usr/bin/docker run --rm \
  14. -v ${RCLONE_CONFIG_PATH}:/etc/rclone.conf \
  15. quay.io/coreos/rclone:latest --config /etc/rclone.conf --checksum=${RCLONE_CHECKSUM} \
  16. copy ${RCLONE_ENDPOINT}/%m ${RCLONE_ENDPOINT}/%m_backup
  17. # Upload new backup
  18. ExecStart=/usr/bin/docker run --rm \
  19. -v ${ETCD_BACKUP_DIR}:/etcd2backup \
  20. -v ${RCLONE_CONFIG_PATH}:/etc/rclone.conf \
  21. quay.io/coreos/rclone:latest --config ${RCLONE_CONFIG_PATH} --checksum=${RCLONE_CHECKSUM} \
  22. copy /etcd2backup/ ${RCLONE_ENDPOINT}/%m/
  23. [Install]
  24. WantedBy=multi-user.target