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

adding

parent 4d42c3f4
[default]
sources=
remote_host=
remote_target=
temp_dir=
gpg_key_id=
gpg_passphrase=
remove_older_than=
## install
```bash
apt install duplicity
pip3 install python-gnupg
pip3 install configparser
pip3 install paramiko
```
```bash
......
......@@ -40,7 +40,7 @@ class Backup:
parser = argparse.ArgumentParser()
# define arguments
parser.add_argument('command', help='start|restore|status|files')
parser.add_argument('command', help='full|incremental|restore|status|files')
# define options
parser.add_argument('-c', '--config', help='full path to config-file')
......@@ -79,6 +79,15 @@ class Backup:
else:
print(message)
#
#
#
#
def _sendmail(self):
if (self._args.sendmail == True):
sendmail = Sendmail(self._logs, 'Backup / ' + self._args.command + ' / ' + platform.uname()[1])
sendmail.run()
#
# generate string for source and adding all
#
......@@ -104,6 +113,7 @@ class Backup:
# if includes is empty
if (includes == ''):
self._log('Error: no sources are found!')
self._sendmail()
exit()
return includes
......@@ -190,7 +200,7 @@ class Backup:
self._create_target()
includes = self._includes()
process = self._command(self._gpg_passphrase() + ' duplicity full ' + includes + ' ' + self._gpg_key_id() + ' ' + self._target())
process = self._command(self._gpg_passphrase() + ' duplicity ' + self._args.command + ' ' + includes + ' ' + self._gpg_key_id() + ' ' + self._target())
self._log(process.stdout)
self._log(process.stderr)
......@@ -257,11 +267,11 @@ class Backup:
self._log(process.stderr)
#
#
# running command
#
#
def run(self):
if (self._args.command == 'start'):
if (self._args.command == 'full' or self._args.command == 'incremental'):
self._start()
self._clean()
elif (self._args.command == 'restore'):
......@@ -271,10 +281,7 @@ class Backup:
elif (self._args.command == 'files'):
self._files()
# send mail
if (self._args.sendmail == True):
sendmail = Sendmail(self._logs, 'Backup / ' + self._args.command + ' / ' + platform.uname()[1])
sendmail.run()
self._sendmail()
# let it rain
backup = Backup()
......
......@@ -106,6 +106,33 @@ class Mysqldump:
else:
self._log(process.stderr)
#
#
#
#
def _create_target:
if os.path.exists(self._args.target):
command = 'rm -R ' + self._args.target
#
#
#
#
def _clean(self):
if not os.path.exists(self._args.target):
command = 'mkdir ' + self._args.target
process = subprocess.run(command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
check=True,
shell=True)
if (process.stderr != ''):
self._log(process.stderr)
#
#
#
......@@ -116,6 +143,8 @@ class Mysqldump:
if (self._args.command == 'all'):
self._all(now)
elif (self._args.command == 'clean'):
self._clean()
# send mail
if (self._args.sendmail == True):
......
......@@ -19,6 +19,7 @@ from email.mime.multipart import MIMEMultipart
#
#
#
#
class Sendmail:
#
......@@ -98,6 +99,7 @@ class Sendmail:
# encrypt message
#
#
#
def _encrypt_message(self, message):
encrypted = MIMEBase('multipart', _subtype='encrypted', protocol='application/pgp-encrypted')
......@@ -125,8 +127,15 @@ class Sendmail:
gpg = gnupg.GPG(gnupghome=gpgpath)
message = str(gpg.encrypt(message.as_string(), self._config['SMTP_TO']))
encrypted_message.set_payload(message)
encrypted_gpg = gpg.encrypt(message.as_string(), self._config['SMTP_TO'])
encrypted_string = str(encrypted_gpg)
# if string is empty, show status and end programm
if encrypted_string == '':
print('Error! ' + encrypted_gpg.status)
exit()
encrypted_message.set_payload(encrypted_string)
encrypted.attach(encrypted_header)
encrypted.attach(encrypted_message)
......
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