Add source

Add initial source files.
This commit is contained in:
Aidan Mullen 2024-01-09 06:53:44 -05:00
parent f0d5dc2303
commit 19fa0a13b6
7 changed files with 213 additions and 0 deletions

60
.gitignore vendored Normal file
View File

@ -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

86
BACKUP/BACKUP.SH Normal file
View File

@ -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"

11
BACKUP/ROOT.SH Normal file
View File

@ -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

6
BACKUP/SCOPE.SH Normal file
View File

@ -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

4
CHANGELOG.MD Normal file
View File

@ -0,0 +1,4 @@
# Full Changelog
## 0.1.0-a.1
- Initial Version

5
LICENSE.MD Normal file
View File

@ -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.

41
README.MD Normal file
View File

@ -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.