Initial commit

This commit is contained in:
2026-04-05 16:23:17 +00:00
commit 6c75e00159
42 changed files with 3859 additions and 0 deletions

40
backup/Dockerfile Normal file
View File

@@ -0,0 +1,40 @@
FROM alpine
# Install required packages
RUN apk add --update --no-cache bash dos2unix
# Install python/pip
#RUN apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python
#RUN python3 -m ensurepip --upgrade
#ENV PYTHONUNBUFFERED=1
# install any Python requirements used by the jobs
#RUN pip3 install colorama
#
RUN apk update && \
apk add mysql-client logrotate rsync perl nano rsnapshot
WORKDIR /usr/scheduler
# Copy files
COPY jobs/*.* ./jobs/
COPY crontab.* ./
COPY logrotate_backup_html ./
COPY logrotate_backup_sql ./
COPY rsnapshot.conf /etc/
COPY start.sh .
# Fix line endings && execute permissions
RUN dos2unix crontab.* *.sh jobs/*.*
#RUN find . -type f -iname "*.sh" -exec chmod +x
#RUN find . -type f -iname "*.py" -exec chmod +x
# create cron.log file
RUN touch /var/log/cron.log
# Run cron on container startup
CMD ["./start.sh"]

View File

@@ -0,0 +1,3 @@
0 3 * * * perl -le 'sleep rand 5000' && /usr/scheduler/jobs/html.sh
0 4 * * * perl -le 'sleep rand 5000' && /usr/scheduler/jobs/sql.sh

22
backup/jobs/html.sh Executable file
View File

@@ -0,0 +1,22 @@
#!/bin/bash
LOCK="/usr/scheduler/backup-html.lock"
if [ -f "$LOCK" ]; then
echo "Another instance of $0 is running, exiting..."
exit 1
fi
touch $LOCK # Creates the file
trap "rm $LOCK" EXIT
echo "Begining backup of HTML files..."
#if [ -f "/srv/backup/html/html.tar.gz" ]; then
# echo "Rotating existing backup files..."
# logrotate /usr/scheduler/logrotate_backup_html
#fi
#echo "Creating tar gzip archive..."
#tar -zcf /srv/backup/html/html.tar.gz /srv/data/html/
rsnapshot daily
echo "Backup finished!"

22
backup/jobs/sql.sh Executable file
View File

@@ -0,0 +1,22 @@
#!/bin/bash
LOCK="/usr/scheduler/backup-mysql.lock"
if [ -f "$LOCK" ]; then
echo "Another instance of $0 is running, exiting..."
exit 1
fi
touch $LOCK # Creates the file
trap "rm $LOCK" EXIT
echo "Beginging backup of DB_1..."
FILE=/srv/backup
if [ -f "/srv/backup/sql/db_1.sql.gz" ]; then
echo "Rotating existing backup files..."
logrotate /usr/scheduler/logrotate_backup_sql
fi
echo "Dumping datbase DB_1..."
mariadb-dump --skip-ssl --opt -h localhost -u root -p$MARIADB_ROOT_PASSWORD db_1 | gzip -c > /srv/backup/sql/db_1.sql.gz
echo "Backup finished!"

View File

@@ -0,0 +1,8 @@
/srv/backup/html/html.tar.gz {
rotate 7
nocompress
extension .gz
dateext
dateyesterday
dateformat .%Y-%m-%d
}

View File

@@ -0,0 +1,9 @@
/srv/backup/sql/db_1.sql.gz {
rotate 60
size 1
nocompress
extension .gz
dateext
dateyesterday
dateformat .%Y-%m-%d
}

17
backup/rsnapshot.conf Normal file
View File

@@ -0,0 +1,17 @@
config_version 1.2
snapshot_root /srv/backup/html
cmd_cp /bin/cp
cmd_rm /bin/rm
cmd_rsync /usr/bin/rsync
cmd_logger /usr/bin/logger
retain daily 60
verbose 2
loglevel 3
lockfile /var/run/rsnapshot.pid
link_dest 1
backup /srv/data/html/ ./ +rsync_long_args=--no-relative

35
backup/start.sh Executable file
View File

@@ -0,0 +1,35 @@
#!/bin/bash
if [ -z "$SCHEDULER_ENVIRONMENT" ]; then
echo "SCHEDULER_ENVIRONMENT not set, assuming Development"
SCHEDULER_ENVIRONMENT="Development"
fi
# Select the crontab file based on the environment
CRON_FILE="crontab.$SCHEDULER_ENVIRONMENT"
#if [ ! -f "/srv/backup" ]; then
# echo "Creating backup directory"
# mkdir /srv/backup/
#fi
if [ ! -f "/srv/backup/html" ]; then
echo "Creating backup directory: HTML"
mkdir /srv/backup/html
fi
if [ ! -f "/srv/backup/sql" ]; then
echo "Creating backup directory: SQL"
mkdir /srv/backup/sql
fi
echo "Loading crontab file: $CRON_FILE"
# Load the crontab file
crontab $CRON_FILE
# Start cron
echo "Starting cron..."
crond -f