-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystem-backup.py
More file actions
executable file
·56 lines (40 loc) · 1.9 KB
/
system-backup.py
File metadata and controls
executable file
·56 lines (40 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Backs up system config. A quick hack for my own use. Useful before
(re)installing a Linux distro.
This script is copyright 2017-20 by Patrick Mooney. It is licensed under the GNU
GPL, either version 3 or (at your option) any later version. See the file
LICENSE.md for details.
"""
import os
import shutil
import subprocess
initial_tar_location = '/home/patrick/'
backup_name = "sys-backup.tar"
working_location = '/home/patrick/.system-config-backup'
try:
os.mkdir(working_location)
except FileExistsError:
pass # Oh well.
backup_file_list = [ '/etc/anacrontab',
'/etc/fstab',
'/etc/hosts',
'/etc/hosts.allow',
'/etc/exports',
'/etc/apt/sources.list*',
'/etc/postfix/*',
'~/.ssh/',
'/root/.ssh/',
working_location
]
backup_file_list = [f for f in backup_file_list if os.path.exists(f)] # Prune any non-existent entries in that list
commands_list = [ 'crontab -l > %s/patrick.cronbak' % working_location, # export user crontab
'sudo crontab -l > %s/root.cronbak' % working_location, # export root crontab
'ls -la / | grep -- "->" > %s/root-symlinks' % working_location, # export list of symlinks at root of drive
'sudo dpkg --get-selections > %s/installed-software.tsv' % working_location, # export list of installed (Debian) pkgs.
]
if __name__ == "__main__":
for which_command in commands_list:
subprocess.call(which_command, shell=True)
# OK, create the archive
subprocess.call('tar -cvf %s/%s %s' % (initial_tar_location, backup_name,' '.join(backup_file_list)), shell=True)