Skip to content

Instantly share code, notes, and snippets.

@Mr-Fox-h
Last active September 24, 2022 07:03
Show Gist options
  • Save Mr-Fox-h/ff5ff957a2dd5eab6f872a5a9863fc0f to your computer and use it in GitHub Desktop.
Save Mr-Fox-h/ff5ff957a2dd5eab6f872a5a9863fc0f to your computer and use it in GitHub Desktop.
Backup system for linux with Python
import os
from os import walk
import shutil
from distutils.dir_util import copy_tree
### Backup WIFI Password On Linux ###
files = os.listdir("/etc/NetworkManager/system-connections/")
os.mkdir("Backup")
os.mkdir("Backup/WIFI_PASS")
num = 1
for line in files:
shutil.copy2("/etc/NetworkManager/system-connections/" + line,
"Backup/WIFI_PASS/WIFI-" + str(num) + ".txt")
num += 1
### Backup Linux Password ###
os.mkdir("Backup/OS_PASS")
os.system("sudo cat /etc/shadow > Backup/OS_PASS/OS_Pass.txt")
### Take Backup ###
os.mkdir("Backup/BackUP")
data_dir = []
for (dirpath, dirnames, filenames) in walk("."):
data_dir.extend(dirnames)
break
for dir in data_dir:
if dir == "Backup":
pass
else:
copy_tree(dir, "Backup/BackUP")
data_file = []
for (dirpath, dirnames, filenames) in walk("."):
data_file.extend(filenames)
break
for file in data_file:
if file == os.path.basename(__file__):
pass
else:
shutil.copy2(file, "Backup/BackUP")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment