]>
git.frykholm.com Git - butterbackup.git/blob - butterbackup.py
a7c7843647573762c0bb2c1acb7188129bc41129
4 from subprocess
import Popen
, PIPE
8 def backup_host(host
, base_dir
, fp
):
9 dest_dir
= os
.path
.join(base_dir
, host
, "latest")
10 if not os
.path
.exists(base_dir
):
11 print("New host",host
,".")
12 run("btrfs subvol create %s"% os
.path
.join(base_dir
, host
))
14 command
= ("rsync -a --numeric-ids --delete --delete-excluded --human-readable --inplace ")
15 excludes
= fp
.readline()[:-1]
16 (stdout
,stderr
) = run(command
+ excludes
+ " root@%s:/ "%(host) + dest_dir
)
21 run("btrfs subvol snapshot %s %s"%(os
.path
.join(base_dir
, host
),os
.path
.join(base_dir
, host
, datetime
.datetime
.now().date().strftime("%F"))))
24 (stdout
, stderr
) = Popen(shlex
.split(cmd
), stdout
=PIPE
).communicate()
26 stdout
= stdout
.decode('utf-8')
28 stderr
= stderr
.decode('utf-8')
29 return(stdout
, stderr
)
31 if __name__
== "__main__":
33 print("You need to be root. Otherwise all permissions will be lost.")
35 base_path
="/etc/butterbackup"
37 if not os
.path
.exists(base_path
):
38 print("No hosts to backup, please place them in",base_path
)
40 hosts
= os
.listdir(base_path
)
42 fp
= open(os
.path
.join(base_path
, host
),"r")
43 backup_host(host
, dest_dir
, fp
)