refactor
This commit is contained in:
parent
9cc56117da
commit
8063b19806
|
@ -8,6 +8,7 @@ import socket
|
||||||
|
|
||||||
int_vars = interface_variables
|
int_vars = interface_variables
|
||||||
|
|
||||||
|
|
||||||
def take_backup():
|
def take_backup():
|
||||||
response = subprocess.Popen(['ping', '-c', '1', 'fileserver.2li.local'])
|
response = subprocess.Popen(['ping', '-c', '1', 'fileserver.2li.local'])
|
||||||
response.wait()
|
response.wait()
|
||||||
|
@ -21,6 +22,7 @@ def take_backup():
|
||||||
print("Server not available")
|
print("Server not available")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
def backup_home():
|
def backup_home():
|
||||||
path_to_backup = "/home/andreas/"
|
path_to_backup = "/home/andreas/"
|
||||||
archive_name = (socket.gethostname() + "-home"
|
archive_name = (socket.gethostname() + "-home"
|
||||||
|
@ -31,6 +33,7 @@ def backup_home():
|
||||||
'::' + archive_name, path_to_backup])
|
'::' + archive_name, path_to_backup])
|
||||||
p.wait()
|
p.wait()
|
||||||
|
|
||||||
|
|
||||||
def backup_vms():
|
def backup_vms():
|
||||||
path_to_backup = "/mnt/sdc/VMs"
|
path_to_backup = "/mnt/sdc/VMs"
|
||||||
archive_name = (socket.gethostname() + "-VMs"
|
archive_name = (socket.gethostname() + "-VMs"
|
||||||
|
@ -40,6 +43,7 @@ def backup_vms():
|
||||||
'::' + archive_name, path_to_backup])
|
'::' + archive_name, path_to_backup])
|
||||||
p.wait()
|
p.wait()
|
||||||
|
|
||||||
|
|
||||||
def prune_home():
|
def prune_home():
|
||||||
archive_name = (socket.gethostname() + "-home")
|
archive_name = (socket.gethostname() + "-home")
|
||||||
p = subprocess.Popen(['borg', 'prune', '--prefix', archive_name,
|
p = subprocess.Popen(['borg', 'prune', '--prefix', archive_name,
|
||||||
|
@ -48,6 +52,7 @@ def prune_home():
|
||||||
'--keep-yearly=1'])
|
'--keep-yearly=1'])
|
||||||
p.wait()
|
p.wait()
|
||||||
|
|
||||||
|
|
||||||
def prune_vms():
|
def prune_vms():
|
||||||
archive_name = (socket.gethostname() + "-VMs")
|
archive_name = (socket.gethostname() + "-VMs")
|
||||||
p = subprocess.Popen(['borg', 'prune', '--prefix', archive_name,
|
p = subprocess.Popen(['borg', 'prune', '--prefix', archive_name,
|
||||||
|
@ -56,8 +61,6 @@ def prune_vms():
|
||||||
'--keep-yearly=1'])
|
'--keep-yearly=1'])
|
||||||
p.wait()
|
p.wait()
|
||||||
|
|
||||||
|
|
||||||
interface_functions.configuration()
|
interface_functions.configuration()
|
||||||
print("config finished")
|
|
||||||
interface_functions.pause()
|
|
||||||
take_backup()
|
take_backup()
|
||||||
print("backup finished")
|
|
||||||
|
|
|
@ -4,11 +4,11 @@ import configparser
|
||||||
import subprocess
|
import subprocess
|
||||||
import interface_variables
|
import interface_variables
|
||||||
import curses
|
import curses
|
||||||
import re
|
|
||||||
|
|
||||||
int_vars = interface_variables
|
int_vars = interface_variables
|
||||||
screen = curses.initscr()
|
screen = curses.initscr()
|
||||||
|
|
||||||
|
|
||||||
def get_param(prompt_string):
|
def get_param(prompt_string):
|
||||||
screen.clear()
|
screen.clear()
|
||||||
screen.border(0)
|
screen.border(0)
|
||||||
|
@ -17,6 +17,7 @@ def get_param(prompt_string):
|
||||||
input = screen.getstr(3, 2, 60)
|
input = screen.getstr(3, 2, 60)
|
||||||
return input
|
return input
|
||||||
|
|
||||||
|
|
||||||
def draw_menu():
|
def draw_menu():
|
||||||
screen.clear()
|
screen.clear()
|
||||||
screen.border(0)
|
screen.border(0)
|
||||||
|
@ -30,6 +31,7 @@ def draw_menu():
|
||||||
screen.addstr(10, 4, "0 - Exit")
|
screen.addstr(10, 4, "0 - Exit")
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
|
|
||||||
|
|
||||||
def draw_screen(r, c, message):
|
def draw_screen(r, c, message):
|
||||||
screen.clear()
|
screen.clear()
|
||||||
screen.border(0)
|
screen.border(0)
|
||||||
|
@ -44,6 +46,7 @@ def list_archives():
|
||||||
borg_list.wait()
|
borg_list.wait()
|
||||||
less_output.wait()
|
less_output.wait()
|
||||||
|
|
||||||
|
|
||||||
def show_info():
|
def show_info():
|
||||||
archive_name = get_param("Please enter the archive name: ").decode('utf-8')
|
archive_name = get_param("Please enter the archive name: ").decode('utf-8')
|
||||||
curses.endwin()
|
curses.endwin()
|
||||||
|
@ -52,6 +55,7 @@ def show_info():
|
||||||
p.wait()
|
p.wait()
|
||||||
pause()
|
pause()
|
||||||
|
|
||||||
|
|
||||||
def mount_archive():
|
def mount_archive():
|
||||||
archive_name = get_param("Please enter the archive name: ").decode('utf-8')
|
archive_name = get_param("Please enter the archive name: ").decode('utf-8')
|
||||||
int_vars.mount_point = os.path.join('/tmp', archive_name)
|
int_vars.mount_point = os.path.join('/tmp', archive_name)
|
||||||
|
@ -61,11 +65,12 @@ def mount_archive():
|
||||||
int_vars.mount_point])
|
int_vars.mount_point])
|
||||||
p.wait()
|
p.wait()
|
||||||
draw_screen(2, 2, "Archive mounted at " + int_vars.mount_point + "/.")
|
draw_screen(2, 2, "Archive mounted at " + int_vars.mount_point + "/.")
|
||||||
screen.addstr(3, 2, "The archive will remain mounted as long this programm "
|
screen.addstr(3, 2, "The archive will remain mounted as long this program "
|
||||||
"is running.")
|
"is running.")
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
ncurses_pause(5)
|
ncurses_pause(5)
|
||||||
|
|
||||||
|
|
||||||
def restore_archive():
|
def restore_archive():
|
||||||
archive_name = get_param("Please enter the archive name: ").decode('utf-8')
|
archive_name = get_param("Please enter the archive name: ").decode('utf-8')
|
||||||
restore_path = get_param("Please enter the path where you want to "
|
restore_path = get_param("Please enter the path where you want to "
|
||||||
|
@ -74,11 +79,12 @@ def restore_archive():
|
||||||
if not os.path.exists(restore_path):
|
if not os.path.exists(restore_path):
|
||||||
os.makedirs(restore_path)
|
os.makedirs(restore_path)
|
||||||
p = subprocess.Popen(['borg', 'extract', '::' + archive_name]
|
p = subprocess.Popen(['borg', 'extract', '::' + archive_name]
|
||||||
,cwd=restore_path)
|
, cwd=restore_path)
|
||||||
p.wait()
|
p.wait()
|
||||||
draw_screen(2, 2, "Archive extracted to " + restore_path)
|
draw_screen(2, 2, "Archive extracted to " + restore_path)
|
||||||
ncurses_pause(5)
|
ncurses_pause(5)
|
||||||
|
|
||||||
|
|
||||||
def delete_archive():
|
def delete_archive():
|
||||||
archive_name = get_param("Please enter the archive name: ").decode('utf-8')
|
archive_name = get_param("Please enter the archive name: ").decode('utf-8')
|
||||||
draw_screen(2, 2, "Please wait while the archive gets deleted.")
|
draw_screen(2, 2, "Please wait while the archive gets deleted.")
|
||||||
|
@ -87,6 +93,7 @@ def delete_archive():
|
||||||
draw_screen(2, 2, "Archive " + archive_name + " deleted")
|
draw_screen(2, 2, "Archive " + archive_name + " deleted")
|
||||||
ncurses_pause(5)
|
ncurses_pause(5)
|
||||||
|
|
||||||
|
|
||||||
def create_archive():
|
def create_archive():
|
||||||
archive_name = get_param("Please enter an archive name: ").decode('utf-8')
|
archive_name = get_param("Please enter an archive name: ").decode('utf-8')
|
||||||
path_to_backup = get_param("Please enter the "
|
path_to_backup = get_param("Please enter the "
|
||||||
|
@ -98,6 +105,7 @@ def create_archive():
|
||||||
draw_screen(2, 2, "Archive of " + path_to_backup + " created.")
|
draw_screen(2, 2, "Archive of " + path_to_backup + " created.")
|
||||||
ncurses_pause(5)
|
ncurses_pause(5)
|
||||||
|
|
||||||
|
|
||||||
def configuration():
|
def configuration():
|
||||||
# setup the config parser
|
# setup the config parser
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
|
@ -113,8 +121,8 @@ def configuration():
|
||||||
config.read(config_file)
|
config.read(config_file)
|
||||||
else:
|
else:
|
||||||
print("Configuration file not found.")
|
print("Configuration file not found.")
|
||||||
exit()
|
sys.exit(0)
|
||||||
# assign the repository variable depending wheter it's a remote or a local
|
# assign the repository variable depending whether it's a remote or a local
|
||||||
# repository
|
# repository
|
||||||
if 'server' in config['DEFAULT']:
|
if 'server' in config['DEFAULT']:
|
||||||
repository = (config['DEFAULT']['user']
|
repository = (config['DEFAULT']['user']
|
||||||
|
@ -131,8 +139,9 @@ def configuration():
|
||||||
os.environ['BORG_REPO'] = repository
|
os.environ['BORG_REPO'] = repository
|
||||||
os.environ['BORG_PASSPHRASE'] = password
|
os.environ['BORG_PASSPHRASE'] = password
|
||||||
|
|
||||||
|
|
||||||
def exit():
|
def exit():
|
||||||
if (not int_vars.mount_point):
|
if not int_vars.mount_point:
|
||||||
curses.endwin()
|
curses.endwin()
|
||||||
os.system('clear')
|
os.system('clear')
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
@ -145,6 +154,7 @@ def exit():
|
||||||
os.rmdir(int_vars.mount_point)
|
os.rmdir(int_vars.mount_point)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
def ncurses_pause(c):
|
def ncurses_pause(c):
|
||||||
screen.border(0)
|
screen.border(0)
|
||||||
screen.addstr(c, 2, "Press Enter to continue...")
|
screen.addstr(c, 2, "Press Enter to continue...")
|
||||||
|
@ -152,5 +162,6 @@ def ncurses_pause(c):
|
||||||
input = screen.getstr(3, 2, 60)
|
input = screen.getstr(3, 2, 60)
|
||||||
return input
|
return input
|
||||||
|
|
||||||
|
|
||||||
def pause():
|
def pause():
|
||||||
input("Press Enter to continue...")
|
input("Press Enter to continue...")
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import os
|
|
||||||
import interface_functions
|
import interface_functions
|
||||||
import interface_variables
|
|
||||||
import curses
|
import curses
|
||||||
|
|
||||||
chosen_activity = None
|
chosen_activity = None
|
||||||
|
|
||||||
# The main menu starts there
|
# The main menu starts there
|
||||||
|
|
|
@ -1,16 +1,61 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
import subprocess
|
import subprocess
|
||||||
import socket
|
|
||||||
import time
|
|
||||||
import interface_functions
|
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
|
import socket
|
||||||
|
import interface_functions
|
||||||
|
|
||||||
path_to_backup = "/home/andreas/"
|
def take_backup():
|
||||||
archive_name = (socket.gethostname() + "-home"
|
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"))
|
+ time.strftime("_%Y-%m-%d_%H:%M"))
|
||||||
|
|
||||||
p = subprocess.Popen(['borg', 'create', '--exclude', '/home/andreas/.cache',
|
p = subprocess.Popen(['borg', 'create', '--exclude', '/home/andreas/.cache',
|
||||||
'--exclude', '/home/andreas/Downloads',
|
'--exclude', '/home/andreas/Downloads',
|
||||||
'::' + archive_name, path_to_backup], stderr=subprocess.PIPE)
|
'::' + archive_name, path_to_backup])
|
||||||
p.wait()
|
p.wait()
|
||||||
|
|
||||||
sys.exit(0)
|
|
||||||
|
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()
|
||||||
|
take_backup()
|
||||||
|
|
Reference in New Issue