-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup.py
More file actions
61 lines (47 loc) · 1.63 KB
/
backup.py
File metadata and controls
61 lines (47 loc) · 1.63 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
57
58
59
60
import datetime
import os
import subprocess
dotfiles_repo_path = "/home/adar/temp_dotfiles"
backup_repo_path = "/home/adar/temp_backup"
def backup():
print("Starting backup")
print("Cloning dotfiles repo")
ret = subprocess.call(['git', 'clone', 'https://github.com/Adar-Dagan/dotfiles.git', dotfiles_repo_path])
if ret != 0:
print("Failed to clone dotfiles repo")
return
print("Cloning backup repo")
ret = subprocess.call(['git', 'clone', 'https://github.com/Adar-Dagan/Backup.git', backup_repo_path])
if ret != 0:
print("Failed to clone backup repo")
return
os.chdir(backup_repo_path)
programs = os.listdir('./programs')
for program in programs:
file_path = f"./programs/{program}"
print("Running " + program + " script")
ret = subprocess.call(['bash', file_path, 'backup', dotfiles_repo_path])
if ret != 0:
print(f"{program} script failed")
return
print("Adding and commiting changes in dotfiles repo")
os.chdir(dotfiles_repo_path)
subprocess.call(['git', 'add', '-A'])
subprocess.call(['git', 'commit', '-m', f'Backup {datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}'])
subprocess.call(['git', 'push'])
def cleanup():
print("Removing temp files")
try:
subprocess.call(['rm', '-rf', dotfiles_repo_path])
except Exception as e:
print(e)
try:
subprocess.call(['rm', '-rf', backup_repo_path])
except Exception as e:
print(e)
if __name__ == "__main__":
try:
backup()
except Exception as e:
print(e)
cleanup()