add bash script backup_to_fileserver and add various changes
to the corresponding python script backup_to_fileserver
This commit is contained in:
parent
eb2f2d73f9
commit
9cc56117da
|
@ -0,0 +1,5 @@
|
||||||
|
#!/bin/bash
|
||||||
|
PATH=$PATH:borg_interface/bin/
|
||||||
|
source borg_interface/bin/activate
|
||||||
|
python3 borg_interface/backup_to_fileserver.py
|
||||||
|
exit 0
|
|
@ -1,5 +1,5 @@
|
||||||
[DEFAULT]
|
[DEFAULT]
|
||||||
# server: fileserver.2li.local
|
#server: fileserver.2li.local
|
||||||
# user: borg
|
#user: borg
|
||||||
repository_path: /home/andreas/test
|
repository_path: /home/andreas/test
|
||||||
password: foo
|
password: foo
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
import subprocess
|
||||||
|
import interface_functions
|
||||||
|
import interface_variables
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
import socket
|
||||||
|
|
||||||
|
int_vars = interface_variables
|
||||||
|
|
||||||
|
def take_backup():
|
||||||
|
response = subprocess.Popen(['ping', '-c', '1', 'fileserver.2li.local'])
|
||||||
|
response.wait()
|
||||||
|
returncode = response.returncode
|
||||||
|
if returncode == 0:
|
||||||
|
backup_home()
|
||||||
|
backup_vms()
|
||||||
|
prune_home()
|
||||||
|
prune_vms()
|
||||||
|
else:
|
||||||
|
print("Server not available")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
def backup_home():
|
||||||
|
path_to_backup = "/home/andreas/"
|
||||||
|
archive_name = (socket.gethostname() + "-home"
|
||||||
|
+ time.strftime("_%Y-%m-%d_%H:%M"))
|
||||||
|
|
||||||
|
p = subprocess.Popen(['borg', 'create', '--exclude', '/home/andreas/.cache',
|
||||||
|
'--exclude', '/home/andreas/Downloads',
|
||||||
|
'::' + archive_name, path_to_backup])
|
||||||
|
p.wait()
|
||||||
|
|
||||||
|
def backup_vms():
|
||||||
|
path_to_backup = "/mnt/sdc/VMs"
|
||||||
|
archive_name = (socket.gethostname() + "-VMs"
|
||||||
|
+ time.strftime("_%Y-%m-%d_%H:%M"))
|
||||||
|
|
||||||
|
p = subprocess.Popen(['borg', 'create',
|
||||||
|
'::' + archive_name, path_to_backup])
|
||||||
|
p.wait()
|
||||||
|
|
||||||
|
def prune_home():
|
||||||
|
archive_name = (socket.gethostname() + "-home")
|
||||||
|
p = subprocess.Popen(['borg', 'prune', '--prefix', archive_name,
|
||||||
|
'--keep-hourly=24', '--keep-daily=7',
|
||||||
|
'--keep-weekly=4', '--keep-monthly=12',
|
||||||
|
'--keep-yearly=1'])
|
||||||
|
p.wait()
|
||||||
|
|
||||||
|
def prune_vms():
|
||||||
|
archive_name = (socket.gethostname() + "-VMs")
|
||||||
|
p = subprocess.Popen(['borg', 'prune', '--prefix', archive_name,
|
||||||
|
'--keep-hourly=24', '--keep-daily=7',
|
||||||
|
'--keep-weekly=4', '--keep-monthly=12',
|
||||||
|
'--keep-yearly=1'])
|
||||||
|
p.wait()
|
||||||
|
|
||||||
|
interface_functions.configuration()
|
||||||
|
print("config finished")
|
||||||
|
interface_functions.pause()
|
||||||
|
take_backup()
|
||||||
|
print("backup finished")
|
|
@ -1,9 +0,0 @@
|
||||||
import os
|
|
||||||
hostname = "google.com" #example
|
|
||||||
response = os.system("ping -c 1 " + hostname)
|
|
||||||
|
|
||||||
#and then check the response...
|
|
||||||
if response == 0:
|
|
||||||
print hostname, 'is up!'
|
|
||||||
else:
|
|
||||||
print hostname, 'is down!'
|
|
|
@ -122,6 +122,7 @@ def configuration():
|
||||||
+ config['DEFAULT']['server']
|
+ config['DEFAULT']['server']
|
||||||
+ ":"
|
+ ":"
|
||||||
+ config['DEFAULT']['repository_path'])
|
+ config['DEFAULT']['repository_path'])
|
||||||
|
int_vars.server = config['DEFAULT']['server']
|
||||||
else:
|
else:
|
||||||
repository = config['DEFAULT']['repository_path']
|
repository = config['DEFAULT']['repository_path']
|
||||||
# assign the password variable
|
# assign the password variable
|
||||||
|
|
|
@ -1,2 +1,4 @@
|
||||||
mount_point = None
|
mount_point = None
|
||||||
archive_name = None
|
archive_name = None
|
||||||
|
server = None
|
||||||
|
std_archive_name = None
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
import subprocess
|
||||||
|
import socket
|
||||||
|
import time
|
||||||
|
import interface_functions
|
||||||
|
import sys
|
||||||
|
|
||||||
|
path_to_backup = "/home/andreas/"
|
||||||
|
archive_name = (socket.gethostname() + "-home"
|
||||||
|
+ time.strftime("_%Y-%m-%d_%H:%M"))
|
||||||
|
|
||||||
|
p = subprocess.Popen(['borg', 'create', '--exclude', '/home/andreas/.cache',
|
||||||
|
'--exclude', '/home/andreas/Downloads',
|
||||||
|
'::' + archive_name, path_to_backup], stderr=subprocess.PIPE)
|
||||||
|
p.wait()
|
||||||
|
|
||||||
|
sys.exit(0)
|
Reference in New Issue