Commit 78523318 authored by Björn's avatar Björn

adding #11 #12

parent 14619b81
[default]
sources=
exclude=
remote_host=
remote_target=
gpg_key_id=
gpg_passphrase=
remove_older_than=
remove_all_but_n_full=
remove_all_inc_of_but_n_full=
[mysql]
username=
password=
temp=
.config
__pycache__
getpass
# Backup (ALPHA)
Small Wrapper for duplicity. It provides a Config-File and try to simpl
Small Wrapper and Helpers for duplicity. It provides a Config-File. This script
supports rsync to upload and download.
## Install
......@@ -30,20 +31,55 @@ export SMTP_TO=""
## Config
If --config not set, the script shows always in current directory.
## Commands
### Backup
Starting backup for full or incremental
```bash
./backup.py full
./back.py incremental
```
Show Status of Backup
```bash
./backup.py status
```
Show Files in Backup
```bash
./backup.py files
```
Restore Backup
```bash
./backup.py restore --d <directory>
```
Restore Backup
```bash
sources=/home/herrhase/Downloads
exclude=
remote_host=test@192.168.56.210
remote_target=backup/der
gpg_key_id=
gpg_passphrase=
remove_all_but_n_full=10
./backup.py restore --d <directory>
```
**[default]**
**sources** files and directories to backup, separated with ","
**exclude** files and directories to ignore, separated with ","
**remote_host** <username>@<host> this script only supports rsync
**remote_target** directory on server to save backup
**gpg_key_recipient** email of gpg_key
**gpg_passphrase** passphrase for gpg_key
**remove_older_than** s, m, h, D, W, M, Y (seconds, minutes, hours, days, weeks, months, years)
**remove_all_but_n_full** count for backups
**remove_all_inc_of_but_n_full** count for backups
### Storagebox
If you use a storagebox from Hetzner you can add and remove SSH-Keys with,
......@@ -85,29 +121,16 @@ temp=
## GPG-Keys
```bash
gpg --list-secret-keys --keyid-format LONG
```
Import gpg-key,
```bash
gpg --import <email>.pub.asc
gpg --edit-key <email>
gpg > trust
Your decision? 5 (Ultimate trust)
```
```bash
remove_older_than=
remove_all_but_n_full=
remove_all_inc_of_but_n_full=
```
Change trust,
```bash
sources=
remote_host=
remote_target=
remote_port=
gpg_key_id=
gpg_passphrase=
remove_older_than=s, m, h, D, W, M, Y (seconds, minutes, hours, days, weeks, months, years)
gpg --edit-key <email>
gpg > trust
Your decision? 5 (Ultimate trust)
```
......@@ -14,6 +14,10 @@
# destination for files
# -f, --force force current action
#
# @author Björn Hase
# @license http://opensource.org/licenses/MIT The MIT License
# @link https://gitlab.tentakelfabrik.de/tentakelfabrik/backup
#
import argparse
import configparser
......@@ -21,6 +25,8 @@ import os
import subprocess
import paramiko
import platform
import gnupg
import getpass
from termcolor import colored
......@@ -107,7 +113,22 @@ class Backup(Config):
#
#
def _gpg_key_id(self):
return '--encrypt-key=' + self._config.get('default', 'gpg_key_id')
if (getpass.getuser() == 'root'):
gpgpath = '/root/.gnupg'
else:
gpgpath = '/home/' + getpass.getuser() + '/.gnupg'
gpg = gnupg.GPG(gnupghome=gpgpath)
keys = gpg.list_keys(True)
for key in keys:
for uid in key['uids']:
if (uid.find(self._config.get('default', 'gpg_key_recipient')) > -1):
gpg_key_id = key['keyid']
break
return '--encrypt-key=' + gpg_key_id
#
# generate string for source and adding all
......@@ -190,21 +211,28 @@ class Backup(Config):
options = ''
# if destination already exists and --force is not set
if (not self._args.destination):
self._log('Destination not set! Please add --d and path to restore files!', 'yellow')
self._log('Restoring failed! Exit Script', 'red')
exit()
# if destination already exists and --force is not set
if (os.path.exists(self._args.destination) and self._args.force == False):
self._log('Error! Destination exists! Add --force to overwrite!')
self._log('Error! Destination exists! Add --force to overwrite!', 'yellow')
self._log('Restoring failed! Exit Script', 'red')
exit()
# adding force
if self._args.force == True:
if self._args.force:
options += ' --force'
# adding time
if self._args.time == True:
if self._args.time:
options += ' --time ' + self._args.time
# adding time
if self._args.file_to_restore == True:
if self._args.file_to_restore:
options += ' --file-to-restore ' + self._args.file_to_restore
process = self._command(self._gpg_passphrase() + ' duplicity restore ' + self._target() + ' ' + self._args.destination + options)
......
This diff is collapsed.
#!/usr/bin/env python3
#
# dump mysql-databases
# dump mysql-databases
#
# usage: mysql.py [-h] [-c CONFIG] [-s] {all,clean}
# usage: mysql.py [-h] [-c CONFIG] [-s] {all,clean}
#
# positional arguments:
# {all,clean} all|clean
# positional arguments:
# {all,clean} all|clean
#
# optional arguments:
# -h, --help show this help message and exit
# -c CONFIG, --config CONFIG
# full path to config-file
# - s, --sendmail send log with
# optional arguments:
# -h, --help show this help message and exit
# -c CONFIG, --config CONFIG
# full path to config-file
# - s, --sendmail send log with
#
#
# https://gitlab.tentakelfabrik.de/tentakelfabrik/backup
# @author Björn Hase
# @license http://opensource.org/licenses/MIT The MIT License
# @link https://gitlab.tentakelfabrik.de/tentakelfabrik/backup
#
import argparse
......
#
# Config
#
# @author Björn Hase
# @license http://opensource.org/licenses/MIT The MIT License
# @link https://gitlab.tentakelfabrik.de/tentakelfabrik/backup
#
import configparser
import os
import subprocess
......
......@@ -2,6 +2,10 @@
# send and encrpty email with gpg
#
#
# @author Björn Hase
# @license http://opensource.org/licenses/MIT The MIT License
# @link https://gitlab.tentakelfabrik.de/tentakelfabrik/backup
#
import os
import gnupg
......
......@@ -9,6 +9,9 @@
# -h, --help show this help message and exit
# -c CONFIG, --config CONFIG full path to config-file
#
# @author Björn Hase
# @license http://opensource.org/licenses/MIT The MIT License
# @link https://gitlab.tentakelfabrik.de/tentakelfabrik/backup
#
import getpass
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment