Created
September 24, 2022 07:00
-
-
Save Mr-Fox-h/94000a6b0e014019e492e46b63c49cad to your computer and use it in GitHub Desktop.
Backup system for linux with Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fileutils' | |
### Backup WIFI Password On Linux ### | |
files = Dir.entries('/etc/NetworkManager/system-connections/').select do |f| | |
File.file? File.join('/etc/NetworkManager/system-connections/', f) | |
end | |
Dir.mkdir('Backup') | |
Dir.mkdir('Backup/WIFI_PASS') | |
num = 1 | |
files.each do |line| | |
data_read = File.read("/etc/NetworkManager/system-connections/#{line}") | |
File.open("Backup/WIFI_PASS/WIFI-#{num}.txt", 'w') do |word| | |
word.puts data_read | |
end | |
num += 1 | |
end | |
### Backup Linux Password ### | |
Dir.mkdir('Backup/OS_PASS') | |
os_pass = File.read('/etc/shadow') | |
File.open('Backup/OS_PASS/OS_Pass.txt', 'w') do |line| | |
line.puts os_pass | |
end | |
### Take Backup ### | |
Dir.mkdir('Backup/BackUP') | |
data_dir = Dir.entries('.').select { |f| File.directory? File.join('.', f) } | |
data_dir.each do |dir| | |
case dir | |
when '.', '..', 'Backup' | |
next | |
else | |
FileUtils.copy_entry dir, 'Backup/BackUP' | |
end | |
end | |
data_file = Dir.entries('.').select { |f| File.file? File.join('.', f) } | |
data_file.each do |file| | |
next if file == __FILE__ | |
FileUtils.cp file, 'Backup/BackUP' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment