From ffd9bf3d39a8c8e8c46e0553933e267853348332 Mon Sep 17 00:00:00 2001 From: k3nny Date: Thu, 28 Nov 2024 23:20:19 +0100 Subject: [PATCH] fix first pass --- .gitignore | 1 + Dockerfile | 23 +++++++++++++++++++++++ compose.yml | 42 ++++++++++++++++++++++++++++++++++++++++++ config.py | 13 ++++++------- cron.sh | 4 ++++ entrypoint.sh | 8 ++++++++ requirements.txt | 6 ++++++ tasks.py | 6 ++++-- tisbackup.py | 36 +++++++++++++++++++----------------- tisbackup_gui.py | 30 ++++++++++++++++-------------- 10 files changed, 129 insertions(+), 40 deletions(-) create mode 100755 Dockerfile create mode 100755 compose.yml mode change 100644 => 100755 config.py create mode 100755 cron.sh create mode 100755 entrypoint.sh mode change 100644 => 100755 requirements.txt diff --git a/.gitignore b/.gitignore index 646274c..5d175cf 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.swp *~ *.pyc +__pycache__/* /tasks.sqlite /tasks.sqlite-wal /srvinstallation diff --git a/Dockerfile b/Dockerfile new file mode 100755 index 0000000..2987976 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +FROM python:3.12-slim + +WORKDIR /opt/tisbackup + +COPY entrypoint.sh /entrypoint.sh +COPY . /opt/tisbackup + +RUN apt update \ + && apt install --no-install-recommends -y rsync ssh cron \ + && rm -rf /var/lib/apt/lists/* + +RUN /usr/local/bin/python3.12 -m pip install --no-cache-dir -r requirements.txt + +RUN mkdir -p /var/spool/cron/crontabs \ + && echo '59 03 * * * root /bin/bash /opt/tisbackup/backup.sh' > /etc/crontab \ + && echo '' >> /etc/crontab \ + && crontab /etc/crontab + +EXPOSE 8080 + +ENTRYPOINT ["/entrypoint.sh"] +CMD ["/usr/local/bin/python3.12","/opt/tisbackup/tisbackup_gui.py"] + diff --git a/compose.yml b/compose.yml new file mode 100755 index 0000000..aec47d0 --- /dev/null +++ b/compose.yml @@ -0,0 +1,42 @@ +services: + tisbackup_gui: + container_name: tisbackup_gui + image: "tisbackup:latest" + build: . + volumes: + - ./config/:/etc/tis/ + - ./backup/:/backup/ + - /etc/timezone:/etc/timezone:ro + - /etc/localtime:/etc/localtime:ro + restart: unless-stopped + ports: + - 9980:8080 + deploy: + resources: + limits: + cpus: 0.50 + memory: 512M + reservations: + cpus: 0.25 + memory: 128M + tisbackup_cron: + container_name: tisbackup_cron + image: "tisbackup:latest" + build: . + volumes: + - ./config/:/etc/tis/ + - ./ssh/:/config_ssh/ + - ./backup/:/backup/ + - /etc/timezone:/etc/timezone:ro + - /etc/localtime:/etc/localtime:ro + restart: always + command: "/bin/bash /opt/tisbackup/cron.sh" + deploy: + resources: + limits: + cpus: 0.50 + memory: 512M + reservations: + cpus: 0.25 + memory: 128M + diff --git a/config.py b/config.py old mode 100644 new mode 100755 index 4488d99..4e1c7ee --- a/config.py +++ b/config.py @@ -1,10 +1,9 @@ -import os,sys -from huey.backends.sqlite_backend import SqliteQueue,SqliteDataStore -from huey.api import Huey, create_task +import os +import sys +from huey.contrib.sql_huey import SqlHuey +from huey.storage import SqliteStorage tisbackup_root_dir = os.path.abspath(os.path.join(os.path.dirname(__file__))) -tasks_db = os.path.join(tisbackup_root_dir,"tasks.sqlite") -queue = SqliteQueue('tisbackups',tasks_db) -result_store = SqliteDataStore('tisbackups',tasks_db) -huey = Huey(queue,result_store,always_eager=False) +tasks_db = os.path.join(tisbackup_root_dir, "tasks.sqlite") +huey = SqlHuey(name="tisbackups",filename=tasks_db,always_eager=False,storage_class=SqliteStorage) diff --git a/cron.sh b/cron.sh new file mode 100755 index 0000000..b5b32b5 --- /dev/null +++ b/cron.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -x +echo "Starting cron job for TIS Backup" +cron -f -l 2 diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..81676cf --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +env >> /etc/environment + +# execute CMD +echo "$@" +exec "$@" + diff --git a/requirements.txt b/requirements.txt old mode 100644 new mode 100755 index 14759fe..db0a55e --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,9 @@ six requests paramiko +pexpect +flask +simplejson +huey +iniparse +redis diff --git a/tasks.py b/tasks.py index c55e1bf..9b8349b 100644 --- a/tasks.py +++ b/tasks.py @@ -1,6 +1,8 @@ -from huey import RedisHuey -import os import logging +import os + +from huey import RedisHuey + from tisbackup import tis_backup huey = RedisHuey('tisbackup', host='localhost') diff --git a/tisbackup.py b/tisbackup.py index aacaf68..de0fd9b 100755 --- a/tisbackup.py +++ b/tisbackup.py @@ -18,37 +18,39 @@ # # ----------------------------------------------------------------------- import datetime +import os import subprocess -import os,sys +import sys from os.path import isfile, join tisbackup_root_dir = os.path.dirname(os.path.realpath(__file__)) sys.path.insert(0,os.path.join(tisbackup_root_dir,'lib')) sys.path.insert(0,os.path.join(tisbackup_root_dir,'libtisbackup')) -from iniparse import ini,ConfigParser -from optparse import OptionParser -import re -import getopt -import os.path -import logging import errno -from libtisbackup.common import * +import getopt +import logging +import os.path +import re +from optparse import OptionParser + +from iniparse import ConfigParser, ini + from libtisbackup.backup_mysql import backup_mysql -from libtisbackup.backup_rsync import backup_rsync -from libtisbackup.backup_rsync import backup_rsync_ssh -#from libtisbackup.backup_oracle import backup_oracle -from libtisbackup.backup_rsync_btrfs import backup_rsync_btrfs -from libtisbackup.backup_rsync_btrfs import backup_rsync__btrfs_ssh -from libtisbackup.backup_pgsql import backup_pgsql -from libtisbackup.backup_xva import backup_xva #from libtisbackup.backup_vmdk import backup_vmdk #from libtisbackup.backup_switch import backup_switch from libtisbackup.backup_null import backup_null -from libtisbackup.backup_xcp_metadata import backup_xcp_metadata -from libtisbackup.copy_vm_xcp import copy_vm_xcp +from libtisbackup.backup_pgsql import backup_pgsql +from libtisbackup.backup_rsync import backup_rsync, backup_rsync_ssh +#from libtisbackup.backup_oracle import backup_oracle +from libtisbackup.backup_rsync_btrfs import (backup_rsync__btrfs_ssh, + backup_rsync_btrfs) #from libtisbackup.backup_sqlserver import backup_sqlserver from libtisbackup.backup_samba4 import backup_samba4 +from libtisbackup.backup_xcp_metadata import backup_xcp_metadata +from libtisbackup.backup_xva import backup_xva +from libtisbackup.common import * +from libtisbackup.copy_vm_xcp import copy_vm_xcp __version__="2.0" diff --git a/tisbackup_gui.py b/tisbackup_gui.py index b928091..57a1102 100755 --- a/tisbackup_gui.py +++ b/tisbackup_gui.py @@ -17,30 +17,32 @@ # along with TISBackup. If not, see . # # ----------------------------------------------------------------------- -import os,sys +import os +import sys from os.path import isfile, join + tisbackup_root_dir = os.path.abspath(os.path.join(os.path.dirname(__file__))) sys.path.append(os.path.join(tisbackup_root_dir,'lib')) sys.path.append(os.path.join(tisbackup_root_dir,'libtisbackup')) -from shutil import * -from iniparse import ConfigParser,RawConfigParser -from libtisbackup.common import * -import time -from flask import request, Flask, session, g, appcontext_pushed, redirect, url_for, abort, render_template, flash, jsonify, Response -from urllib.parse import urlparse -import json import glob -import time - -from config import huey -from tasks import run_export_backup, get_task, set_task - -from tisbackup import tis_backup +import json import logging import re +import time +from shutil import * +from urllib.parse import urlparse +from flask import (Flask, Response, abort, appcontext_pushed, flash, g, + jsonify, redirect, render_template, request, session, + url_for) +from iniparse import ConfigParser, RawConfigParser + +from config import huey +from libtisbackup.common import * +from tasks import get_task, run_export_backup, set_task +from tisbackup import tis_backup cp = ConfigParser() cp.read("/etc/tis/tisbackup_gui.ini")