From 19fa0a13b6cfa6a1a32123b338552da64ed47ffb Mon Sep 17 00:00:00 2001 From: Aidan Mullen Date: Tue, 9 Jan 2024 06:53:44 -0500 Subject: [PATCH] Add source Add initial source files. --- .gitignore | 60 +++++++++++++++++++++++++++++++++ BACKUP/BACKUP.SH | 86 ++++++++++++++++++++++++++++++++++++++++++++++++ BACKUP/ROOT.SH | 11 +++++++ BACKUP/SCOPE.SH | 6 ++++ CHANGELOG.MD | 4 +++ LICENSE.MD | 5 +++ README.MD | 41 +++++++++++++++++++++++ 7 files changed, 213 insertions(+) create mode 100644 .gitignore create mode 100644 BACKUP/BACKUP.SH create mode 100644 BACKUP/ROOT.SH create mode 100644 BACKUP/SCOPE.SH create mode 100644 CHANGELOG.MD create mode 100644 LICENSE.MD create mode 100644 README.MD diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fd828b6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,60 @@ +# Directories +./target +./debug + +# Binaries +*.exe +*.x86_64 +*.hex +*.app +*.out +*.i*86 + +# Dependencies +*.d + +# Libraries +*.a +*.lib +*.lai +*.la +*.lo + +# Headers +*.gch +*.pch + +# Objects +*.dll +*.dylib +*.so +*.so.* +*.slo +*.lo +*.o +*.ko +*.elf +*.obj + +# Linking +*.map +*.exp +*.ilk + +# Kernel +*.cmd +modules.order +Module.symvers +dkms.conf +Mkfile.old +*.mod* +*.mod +*.smod + +# Auto-Generated Files +*.pdb +Cargo.lock +**/*.rs.bk +*.dSYM/ +*.su +*.idb diff --git a/BACKUP/BACKUP.SH b/BACKUP/BACKUP.SH new file mode 100644 index 0000000..b540d15 --- /dev/null +++ b/BACKUP/BACKUP.SH @@ -0,0 +1,86 @@ +#!/bin/bash +# Primary backup script containing incremental backup commands. + +# More comments will be added in the future. + +# Backup Script + +version="v0.1.0-a.1" + +# Add "-a" flag between "--bwlimit=1000" and "--backup" for async (higher CPU usage). + +# Color-Coding + +white='\e[0;37m' +green='\e[0;32m' +yellow='\e[0;33m' +red='\e[0;31m' + +echo -e "${white}" + +echo -e "${yellow}Running ${green}${version}${white}\n" + +# Remove Existing Archives + +echo -e "${yellow}Removing old archives.${white}\n" + +sudo rm /path/to/service/services.7z +sudo rm /path/to/service/services.7z.* + +sudo rm /var/www/html.7z +sudo rm /var/www/html.7z.* + +sudo rm /opt/opt.7z +sudo rm /opt/opt.7z.* + +echo -e "\n${green}Finished.${white}\n" + +# Incremental Backups + +echo -e "${yellow}Creating backup archives.${white}\n" + +cd /path/to/service +sudo nice -n11 ionice --class 2 7zz a services + +sudo nice -n11 ionice --class 2 rsync --bwlimit=1000 -a --backup --whole-file --suffix=`date +'.%F_%H-%M'` /path/to/service/services.7z /path/to/backups/path/to/service.7z + +#cd /var/www/html +#sudo nice -n11 ionice --class 2 sudo 7zz a html +#sudo nice -n11 ionice --class 2 rsync --bwlimit=1000 -a --backup --whole-file --suffix=`date +'.%F_%H-%M'` /var/www/html/html.7z /path/to/backups/var/www/html.7z + +cd /opt +sudo nice -n11 ionice --class 2 7zz a opt +sudo nice -n11 ionice --class 2 rsync --bwlimit=1000 -a --backup --whole-file --suffix=`date +'.%F_%H-%M'` /opt/opt.7z /path/to/backups/opt.7z + +sudo nice -n11 ionice --class 2 sudo rsync -rtDvz /var/spool/cron root/backup/var/spool/cron +sudo nice -n11 ionice --class 2 sudo rsync -rtDvz /etc/fstab root/backup/etc/fstab +sudo nice -n11 ionice --class 2 sudo rsync -rtDvz /etc/sudoers root/backup/etc/sudoers +sudo nice -n11 ionice --class 2 sudo rsync -rtDvz /etc/apt/sources.list /path/to/backups/etc/apt + +# Full Backups + +sudo nice -n11 ionice --class 2 rsync --bwlimit=1000 -a --backup --whole-file --suffix=`date +'.%F_%H-%M'` /path/to/service/services.7z /path/to/full-backups/path/to/service.7z +sudo nice -n11 ionice --class 2 rsync --bwlimit=1000 -a --backup --whole-file --suffix=`date +'.%F_%H-%M'` /var/www/html/html.7z /path/to/full-backups/var/www/html.7z +sudo nice -n11 ionice --class 2 rsync --bwlimit=1000 -a --backup --whole-file --suffix=`date +'.%F_%H-%M'` /opt/opt.7z /path/to/backups/opt.7z + +sudo nice -n11 ionice --class 2 sudo rsync -rtDvz /var/spool/cron /path/to/full-backups/var/spool/cron +sudo nice -n11 ionice --class 2 sudo rsync -rtDvz /etc/fstab /path/to/full-backups/etc/fstab +sudo nice -n11 ionice --class 2 sudo rsync -rtDvz /etc/sudoers /path/to/full-backups/etc/sudoers +sudo nice -n11 ionice --class 2 sudo rsync -rtDvz /etc/apt/sources.list /path/to/full-backups/etc/apt + +echo -e "\n${green}Complete.${white}\n" + +# Remove Leftovers + +echo -e "${yellow}Removing leftovers.${white}\n" + +sudo rm /path/to/service/services.7z +sudo rm /path/to/service/services.7z.* + +sudo rm /var/www/html.7z +sudo rm /var/www/html.7z.* + +sudo rm /opt/opt.7z +sudo rm /opt/opt.7z.* + +echo -e "\n${green}Complete.${white}\n" diff --git a/BACKUP/ROOT.SH b/BACKUP/ROOT.SH new file mode 100644 index 0000000..e769c5a --- /dev/null +++ b/BACKUP/ROOT.SH @@ -0,0 +1,11 @@ +#!/bin/bash +# Full system backup script. + +# More comments will be added in the future. + +# Full Backup + +cd ../../../ +sudo 7zz a root-backup +sudo rsync -a --backup --suffix=`date +'.%F_%H-%M'` root-backup.7z /path/to/backups/root-backup.7z +sudo rm root-backup.7z diff --git a/BACKUP/SCOPE.SH b/BACKUP/SCOPE.SH new file mode 100644 index 0000000..a9da075 --- /dev/null +++ b/BACKUP/SCOPE.SH @@ -0,0 +1,6 @@ +#!/bin/bash +# Startup script for backups. + +# More comments will be added in the future. + +sudo systemd-run --scope --uid=0 -p CPUQuota=10% -p MemoryMax=512M bash /path/to/BACKUP.SH diff --git a/CHANGELOG.MD b/CHANGELOG.MD new file mode 100644 index 0000000..f46e074 --- /dev/null +++ b/CHANGELOG.MD @@ -0,0 +1,4 @@ +# Full Changelog + +## 0.1.0-a.1 +- Initial Version diff --git a/LICENSE.MD b/LICENSE.MD new file mode 100644 index 0000000..3c6333a --- /dev/null +++ b/LICENSE.MD @@ -0,0 +1,5 @@ +Copyright (c) 2024 Aidan Mullen + +Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/README.MD b/README.MD new file mode 100644 index 0000000..e5b11da --- /dev/null +++ b/README.MD @@ -0,0 +1,41 @@ +# Backup-System +### These scripts are in a very early state, so caution is advised. +### **Proper documentation will be provided at a later date.** + +A collection of Bash scripts for generating backup archives; these scripts are primarily intended for personal servers. + +Currently, the scripts and their documentation are a work-in-progress. + +Eventually, the documentation will be located in `/DOCUMENTATION`. + +## Summary +### Current method of documentation. + +To archive the files, the scripts use 7-zip, then they copy the files to another directory (preferably another drive) using Rsync; the archive-name contains the time of the backup. + +### Required Software + +- 7-zip +- Rsync +- ionice +- nice +- systemd + +Install: + +``` +$ apt install 7z +$ apt install rsync +``` + +- At the moment, each dependency must be installed manually; however, a script will be provided later to automate this process. +- To run the backup automatically, create a cronjob: + `$ crontab -e` + + Add the following: + `0 5 * * * sudo bash /path/to/scope.sh` + +- For the time being, each script will require manual configuration: + - Replace each `/path/to/...` with your desired directory. + - Edit `SCOPE.SH` to allocate a greater amount of the RAM and CPU, as the default values are too low. +