initial commit

This commit is contained in:
2025-08-13 22:51:13 -03:00
commit 68377fc083
13 changed files with 35400 additions and 0 deletions

25
backup/backup_arr.sh Normal file
View File

@@ -0,0 +1,25 @@
#!/bin/bash
# Set the source and destination paths
source_path=~/
backup_path=/mnt/server_backup/arr/
timestamp=$(date "+%Y%m%d_%H%M%S")
log_path=~/scripts/
# Stop containers
docker stop $(docker ps -q)
# Create a tar archive excluding cache and hidden files
file_name="${timestamp}_arr_backup.tar.gz"
tar -czf $source_path$file_name --exclude=*/cache --exclude=*/blobs --exclude=*/generated --exclude=*/MediaCover --exclude=*/logs --exclude=*/Cache --exclude=*/Logs --exclude=*/Metadata --exclude=*/Crash\ Reports --exclude=*/Media --exclude=~/.* $source_path
# Use rsync to copy the created archive to the destination
rsync -av --progress "${source_path}${file_name}" "$backup_path"
# Optionally, remove the local backup file after copying
rm $source_path$file_name
# Restart containers
docker start $(docker ps -a -q)
echo "${file_name} - backup complete" >> ${log_path}backup.log

31
backup/backup_services.sh Normal file
View File

@@ -0,0 +1,31 @@
#!/bin/bash
# Set the source and destination paths
source_path=/home/ccalifice/
backup_path=/mnt/server_backup/services/
timestamp=$(date "+%Y%m%d_%H%M%S")
# Stop containers
echo "stopping containers" >> ${source_path}backup.log
docker stop $(docker ps -q)
# Create a tar archive excluding cache and hidden files
file_name="${timestamp}_services_backup.tar.gz"
echo "Creating archive $source_path$file_name" >> ${source_path}backup.log
tar -czf $source_path$file_name --exclude=*/cache --exclude=*/logs --exclude=*/Cache --exclude=*/Logs --exclude=*/photoprism/storage --exclude=*/model-cache --exclude=*/immich-app/library $source_path
# Use rsync to copy the created archive to the destination
rsync -av --progress "${source_path}${file_name}" "$backup_path"
# Optionally, remove the local backup file after copying
rm $source_path$file_name
# Restart containers
echo "starting containers" >> ${source_path}backup.log
docker start $(docker ps -a -q)
echo "${file_name} - backup complete" >> ${source_path}backup.log

2
backup/exclude_file.txt Normal file
View File

@@ -0,0 +1,2 @@
#exclude mounted partitions
/mnt

4
backup/include_file.txt Normal file
View File

@@ -0,0 +1,4 @@
#include the following paths in backup
/home
/etc
/var/lib/docker/volumes

76
backup/restic_backup.sh Normal file
View File

@@ -0,0 +1,76 @@
#!/bin/bash
user=$1
# Set the source and destination paths
include_file=/home/$user/scripts/backup/include_file.txt
exclude_file=/home/$user/scripts/backup/exclude_file.txt
respository=/mnt/restic/
timestamp=$(date "+%Y-%m-%d_%H:%M:%S")
log_file=/home/$user/scripts/backup/restic_log.log
restic_repo="/mnt/restic"
echo "${timestamp} Starting backup" >> $log_file
echo "User: ${user}" >> $log_file
export RESTIC_PASSWORD=asdf1234
# Stop containers
echo "${timestamp} Stopping containers" >> $log_file
#docker stop $(docker ps -q) >> $log_file
for dir in /home/$user/*; do
# Remove trailing slash
dir=${dir%/}
# Check if it is a directory and does NOT end with "DISABLED"
if [[ -d "$dir" && ! "$dir" =~ DISABLED$ ]]; then
if [ -f "$dir/docker-compose.yml" ]; then
echo "Bringing down Docker Compose in $dir" >> $log_file
(cd "$dir" && docker compose down)
else
echo "No docker-compose.yml found in $dir, skipping." >> $log_file
fi
else
echo "Project is disabled. Skipping $dir" >> $log_file
fi
done
restic_command="restic -r ${restic_repo} backup --files-from ${include_file} --exclude-file=${exclude_file}"
echo "${timestamp} Starting restic backup. Command: ${restic_command}" >> $log_file
# Run restic backup
$restic_command >> $log_file
# Restart containers
echo "Restarting containers" >> $log_file
#docker start $(docker ps -a -q) >> $log_file
for dir in /home/$user/*; do
# Remove trailing slash
dir=${dir%/}
# Check if it is a directory and does NOT end with "DISABLED"
if [[ -d "$dir" && ! "$dir" =~ DISABLED$ ]]; then
if [ -f "$dir/docker-compose.yml" ]; then
echo "Bringing up Docker Compose in $dir" >> $log_file
(cd "$dir" && docker compose up -d)
else
echo "No docker-compose.yml found in $dir, skipping." >> $log_file
fi
else
echo "Project is disabled. Skipping $dir" >> $log_file
fi
done
echo "${timestamp} Backup complete." >> $log_file
# Remove old backups with policy
forget_command="restic -r ${restic_repo} forget --keep-daily 2 --keep-weekly 1 --keep-monthly 1 --keep-yearly 1 --prune"
echo "${timestamp} Removing old backups. Command: ${forget_command}" >> $log_file
$forget_command >> $log_file
echo "${timestamp} Backup script done" >> $log_file

35051
backup/restic_log.log Normal file

File diff suppressed because it is too large Load Diff

42
backup/restore_script.py Normal file
View File

@@ -0,0 +1,42 @@
import tarfile
import shutil
import os
import glob
def extract_tar_gz(source_file, destination_dir, extract_path):
# Ensure destination directory exists
os.makedirs(destination_dir, exist_ok=True)
# Extract files from tar.gz file
with tarfile.open(source_file, "r:gz") as tar:
for member in tar.getmembers():
if member.name.startswith(extract_path):
tar.extract(member, destination_dir)
def main():
# Source file pattern
source_pattern = "/mnt/server_backup/restore/*.tar.gz"
# Destination directory
destination_dir = "/home/ccalifice/"
# Path inside the tarfile to extract
extract_path = "home/ccalifce/"
# Get list of tar.gz files
tar_files = glob.glob(source_pattern)
if not tar_files:
print("No matching tar.gz files found.")
return
# Copy and extract each tar.gz file
for source_file in tar_files:
try:
extract_tar_gz(source_file, destination_dir, extract_path)
print(f"Extraction successful for {source_file}.")
except Exception as e:
print(f"Error extracting {source_file}: {e}")
if __name__ == "__main__":
main()