Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 622e257145 | |||
| 7e66dad7e7 | |||
| 69fb566e8a | |||
| 3e993f65e6 | |||
| 3cffa4f601 | |||
| adc484cc26 | |||
| c99e61ac45 | |||
| e1e488f723 | |||
| 0562aee04b | |||
| b1c104f36c | |||
| 5afe05b2d2 | |||
| 7207fef0d4 | |||
| 3f9fae10af |
@@ -1,11 +0,0 @@
|
||||
NUITKA_BUILD=0
|
||||
INVENTAR_HTTP_PORT=10000
|
||||
INVENTAR_HTTP_PORTS=10000
|
||||
INVENTAR_APP_IMAGE=ghcr.io/aiirondev/legendary-octo-garbanzo:v0.7.42
|
||||
INVENTAR_APP_CPUS=1.0
|
||||
INVENTAR_APP_MEM_LIMIT=384m
|
||||
INVENTAR_APP_MEM_SWAP_LIMIT=768m
|
||||
INVENTAR_WORKERS=4
|
||||
INVENTAR_THREADS=2
|
||||
INVENTAR_WORKER_TIMEOUT=30
|
||||
INVENTAR_WORKER_CONNECTIONS=100
|
||||
@@ -256,7 +256,7 @@ jobs:
|
||||
EOF
|
||||
|
||||
# Copy runtime scripts and config if present
|
||||
for f in start.sh stop.sh restart.sh backup.sh config.json update.sh; do
|
||||
for f in start.sh stop.sh restart.sh backup.sh restore.sh config.json update.sh; do
|
||||
if [ -f "$f" ]; then
|
||||
cp "$f" "release-bundle/$(basename "$f")"
|
||||
fi
|
||||
|
||||
+83
-79
@@ -289,7 +289,7 @@ SCHEDULER_INTERVAL = cfg.SCHEDULER_INTERVAL_MIN
|
||||
SSL_CERT = cfg.SSL_CERT
|
||||
SSL_KEY = cfg.SSL_KEY
|
||||
|
||||
LIBRARY_ITEM_TYPES = ('book', 'cd', 'dvd', 'other', 'schoolbook', 'Buch', 'Schulbuch', 'schulbuch')
|
||||
LIBRARY_ITEM_TYPES = ('book', 'cd', 'dvd', 'schoolbook', 'Buch', 'Schulbuch', 'schulbuch')
|
||||
INVOICE_CURRENCY = 'EUR'
|
||||
|
||||
NOTIFICATION_STATUS_CACHE_TTL = max(3, int(os.getenv('INVENTAR_NOTIFICATION_STATUS_CACHE_TTL', '8')))
|
||||
@@ -3075,6 +3075,9 @@ def library_loans_admin():
|
||||
|
||||
_ensure_audit_indexes_once()
|
||||
|
||||
# IMPORT HINZUGEFÜGT: Entschlüsselungs-Tool importieren
|
||||
from modules.inventarsystem.data_protection import decrypt_text
|
||||
|
||||
def fmt_dt(dt):
|
||||
try:
|
||||
return dt.strftime('%d.%m.%Y %H:%M') if dt else ''
|
||||
@@ -3121,6 +3124,9 @@ def library_loans_admin():
|
||||
item_has_damage = bool(item_doc.get('HasDamage')) or condition_value == 'destroyed' or bool(item_doc.get('DamageReports'))
|
||||
damage_reports = item_doc.get('DamageReports', []) or []
|
||||
|
||||
raw_user = record.get('User', '')
|
||||
decrypted_user = decrypt_text(raw_user) if raw_user else ''
|
||||
|
||||
loan_entries.append({
|
||||
'id': str(record.get('_id')),
|
||||
'item_id': item_id,
|
||||
@@ -3128,7 +3134,7 @@ def library_loans_admin():
|
||||
'item_code': item_doc.get('Code_4', ''),
|
||||
'item_author': item_doc.get('Author', ''),
|
||||
'item_isbn': item_doc.get('ISBN', ''),
|
||||
'user': record.get('User', ''),
|
||||
'user': decrypted_user,
|
||||
'status': record.get('Status', ''),
|
||||
'start': fmt_dt(record.get('Start')),
|
||||
'end': fmt_dt(record.get('End')),
|
||||
@@ -3181,7 +3187,6 @@ def library_loans_admin():
|
||||
if client:
|
||||
client.close()
|
||||
|
||||
|
||||
@app.route('/api/library_items')
|
||||
def api_library_items():
|
||||
"""
|
||||
@@ -3212,7 +3217,7 @@ def api_library_items():
|
||||
ausleihungen_db = db['ausleihungen']
|
||||
|
||||
query = {
|
||||
'ItemType': {'$in': ['book', 'cd', 'dvd', 'other', 'schoolbook', 'schulbuch', 'Buch', 'Schulbuch']},
|
||||
'ItemType': {'$in': ['book', 'cd', 'dvd', 'schoolbook', 'schulbuch', 'Buch', 'Schulbuch']},
|
||||
'IsGroupedSubItem': {'$ne': True},
|
||||
'Deleted': {'$ne': True}
|
||||
}
|
||||
@@ -3338,7 +3343,7 @@ def api_library_items():
|
||||
client = MongoClient(cfg.MONGODB_HOST, cfg.MONGODB_PORT)
|
||||
db = client[cfg.MONGODB_DB]
|
||||
student_cards = db['student_cards']
|
||||
card = student_cards.find_one({'_id': ObjectId(borrow_id)})
|
||||
card = student_cards.find_one({'_id': ObjectId(borrower)}) if borrower else None
|
||||
card = _decrypt_student_card_doc(card)
|
||||
client.close()
|
||||
borrower = card['SchülerName']
|
||||
@@ -8048,6 +8053,8 @@ def admin_borrowings():
|
||||
|
||||
_ensure_audit_indexes_once()
|
||||
|
||||
from modules.inventarsystem.data_protection import decrypt_text
|
||||
|
||||
client = MongoClient(MONGODB_HOST, MONGODB_PORT)
|
||||
db = client[MONGODB_DB]
|
||||
ausleihungen = db['ausleihungen']
|
||||
@@ -8081,6 +8088,10 @@ def admin_borrowings():
|
||||
item_name = None
|
||||
item_cost = None
|
||||
has_damage = False
|
||||
|
||||
raw_user = r.get('User', '')
|
||||
decrypted_user = decrypt_text(raw_user) if raw_user else ''
|
||||
|
||||
entries.append({
|
||||
'id': str(r.get('_id')),
|
||||
'item_id': str(item_doc.get('_id')) if item_doc and item_doc.get('_id') else str(it_id or ''),
|
||||
@@ -8088,7 +8099,7 @@ def admin_borrowings():
|
||||
'item_name': str(item_name or ''),
|
||||
'item_cost': fmt_money(item_cost),
|
||||
'item_cost_raw': item_cost if item_cost is not None else '',
|
||||
'user': r.get('User', ''),
|
||||
'user': decrypted_user,
|
||||
'status': r.get('Status', ''),
|
||||
'start': fmt_dt(r.get('Start')),
|
||||
'end': fmt_dt(r.get('End')),
|
||||
@@ -8154,10 +8165,26 @@ def admin_audit_dashboard():
|
||||
|
||||
# DEC_START: Decrypt the sensitive fields for display
|
||||
for row in audit_rows:
|
||||
if "payload" in row:
|
||||
# decrypt_document_fields acts in-place
|
||||
decrypt_document_fields(row["payload"], SENSITIVE_AUDIT_FIELDS)
|
||||
# DEC_END
|
||||
payload_raw = row.get("payload")
|
||||
|
||||
if payload_raw and isinstance(payload_raw, str):
|
||||
try:
|
||||
# Safely evaluate the python-like dict string, providing context for ObjectId
|
||||
safe_context = {"ObjectId": ObjectId, "None": None, "True": True, "False": False}
|
||||
payload_dict = eval(payload_raw, {"__builtins__": {}}, safe_context)
|
||||
|
||||
if isinstance(payload_dict, dict):
|
||||
# Decrypt the sensitive keys inside the extracted dictionary
|
||||
decrypt_document_fields(payload_dict, SENSITIVE_AUDIT_FIELDS)
|
||||
|
||||
# Replace the raw string with the clean dictionary for the Jinja template
|
||||
row["payload"] = payload_dict
|
||||
except Exception as parse_err:
|
||||
app.logger.error(f"Failed to parse audit payload string for index {row.get('chain_index')}: {parse_err}")
|
||||
|
||||
elif payload_raw and isinstance(payload_raw, dict):
|
||||
# Fallback in case some newer log rows are already stored as proper dictionaries
|
||||
decrypt_document_fields(payload_raw, SENSITIVE_AUDIT_FIELDS)
|
||||
|
||||
return render_template(
|
||||
'admin_audit.html',
|
||||
@@ -8204,11 +8231,26 @@ def admin_audit_export_pdf_official():
|
||||
|
||||
audit_rows = list(db['audit_log'].find({}).sort('chain_index', -1).limit(limit))
|
||||
|
||||
# DEC_START: Decrypt sensitive fields for the PDF report
|
||||
for row in audit_rows:
|
||||
if "payload" in row:
|
||||
decrypt_document_fields(row["payload"], SENSITIVE_AUDIT_FIELDS)
|
||||
# DEC_END
|
||||
payload_raw = row.get("payload")
|
||||
|
||||
if payload_raw and isinstance(payload_raw, str):
|
||||
try:
|
||||
# Safely evaluate the python-like dict string with custom token support
|
||||
safe_context = {"ObjectId": ObjectId, "None": None, "True": True, "False": False}
|
||||
payload_dict = eval(payload_raw, {"__builtins__": {}}, safe_context)
|
||||
|
||||
if isinstance(payload_dict, dict):
|
||||
# Decrypt the dictionary fields in-place
|
||||
decrypt_document_fields(payload_dict, SENSITIVE_AUDIT_FIELDS)
|
||||
# Replace string with the clean dictionary so the PDF generator can read it
|
||||
row["payload"] = payload_dict
|
||||
except Exception as parse_err:
|
||||
app.logger.error(f"Failed to parse audit payload string for PDF export at index {row.get('chain_index')}: {parse_err}")
|
||||
|
||||
elif payload_raw and isinstance(payload_raw, dict):
|
||||
# Fallback for standard dict payloads
|
||||
decrypt_document_fields(payload_raw, SENSITIVE_AUDIT_FIELDS)
|
||||
|
||||
# Get school information from settings or use defaults
|
||||
school_info = _get_school_info_for_export()
|
||||
@@ -10366,91 +10408,53 @@ def notifications_unread_status():
|
||||
client.close()
|
||||
|
||||
|
||||
@app.route('/admin/damaged_items')
|
||||
@app.route('/admin/damaged_items')
|
||||
def admin_damaged_items():
|
||||
"""Dedicated admin management window for damaged items."""
|
||||
"""Admin-Übersicht aller aktiven und vergangenen Ausleihen."""
|
||||
if 'username' not in session:
|
||||
flash('Administratorrechte erforderlich.', 'error')
|
||||
return redirect(url_for('login'))
|
||||
|
||||
'''
|
||||
permissions = _get_current_user_permissions()
|
||||
if not _action_access_allowed(permissions, 'can_manage_settings'):
|
||||
flash('Sie haben keine Berechtigung, die Schulstammdaten zu ändern.', 'error')
|
||||
if cfg.MODULES.is_enabled('library'):
|
||||
return redirect(url_for('library_admin'))
|
||||
'''
|
||||
|
||||
from modules.inventarsystem.data_protection import decrypt_text
|
||||
from bson.objectid import ObjectId
|
||||
|
||||
client = None
|
||||
try:
|
||||
client = MongoClient(MONGODB_HOST, MONGODB_PORT)
|
||||
db = client[MONGODB_DB]
|
||||
items_col = db['items']
|
||||
ausleihungen_col = db['ausleihungen']
|
||||
items_col = db['items']
|
||||
|
||||
items = list(items_col.find(
|
||||
{
|
||||
'Deleted': {'$ne': True},
|
||||
'$or': [
|
||||
{'HasDamage': True},
|
||||
{'Condition': 'destroyed'},
|
||||
{'DamageReports.0': {'$exists': True}},
|
||||
]
|
||||
},
|
||||
{
|
||||
'Name': 1,
|
||||
'Code_4': 1,
|
||||
'ItemType': 1,
|
||||
'Author': 1,
|
||||
'ISBN': 1,
|
||||
'Condition': 1,
|
||||
'DamageReports': 1,
|
||||
'DamageRepairs': 1,
|
||||
'Verfuegbar': 1,
|
||||
'User': 1,
|
||||
'LastUpdated': 1,
|
||||
}
|
||||
).sort('LastUpdated', -1))
|
||||
ausleihungen = list(ausleihungen_col.find().sort('Start', -1))
|
||||
|
||||
damaged_rows = []
|
||||
for item_doc in items:
|
||||
item_id = str(item_doc.get('_id'))
|
||||
active_borrow = ausleihungen_col.find_one(
|
||||
{'Item': item_id, 'Status': {'$in': ['active', 'planned']}},
|
||||
{'_id': 1, 'User': 1, 'Status': 1, 'End': 1}
|
||||
)
|
||||
reports = item_doc.get('DamageReports', []) or []
|
||||
latest_report = reports[0] if reports else {}
|
||||
for record in ausleihungen:
|
||||
raw_user = record.get('User', '')
|
||||
if raw_user:
|
||||
record['User'] = decrypt_text(raw_user)
|
||||
|
||||
damaged_rows.append({
|
||||
'id': item_id,
|
||||
'name': item_doc.get('Name', ''),
|
||||
'code': item_doc.get('Code_4', ''),
|
||||
'item_type': item_doc.get('ItemType', ''),
|
||||
'author': item_doc.get('Author', ''),
|
||||
'isbn': item_doc.get('ISBN', ''),
|
||||
'condition': item_doc.get('Condition', ''),
|
||||
'available': bool(item_doc.get('Verfuegbar', False)),
|
||||
'borrow_user': item_doc.get('User', ''),
|
||||
'damage_count': len(reports),
|
||||
'damage_reports': reports,
|
||||
'latest_damage_description': latest_report.get('description', ''),
|
||||
'latest_damage_by': latest_report.get('reported_by', ''),
|
||||
'latest_damage_at': latest_report.get('reported_at'),
|
||||
'active_borrow': active_borrow,
|
||||
'last_updated': item_doc.get('LastUpdated'),
|
||||
})
|
||||
item_id = record.get('Item')
|
||||
if item_id:
|
||||
try:
|
||||
item_doc = items_col.find_one({'_id': ObjectId(item_id)})
|
||||
if item_doc:
|
||||
if item_doc.get('User'):
|
||||
item_doc['User'] = decrypt_text(item_doc['User'])
|
||||
|
||||
record['ItemDetails'] = item_doc
|
||||
except Exception as e:
|
||||
app.logger.warning(f"Konnte Item {item_id} für Ausleihe {record.get('_id')} nicht laden: {e}")
|
||||
|
||||
return render_template(
|
||||
'admin_damaged_items.html',
|
||||
damaged_items=damaged_rows,
|
||||
'admin_damaged_items.html',
|
||||
ausleihungen=ausleihungen,
|
||||
library_module_enabled=cfg.MODULES.is_enabled('library'),
|
||||
student_cards_module_enabled=cfg.MODULES.is_enabled('student_cards'),
|
||||
mail_module_enabled=cfg.MODULES.is_enabled('mail')
|
||||
)
|
||||
|
||||
except Exception as exc:
|
||||
app.logger.error(f"Error loading damaged-items admin view: {exc}")
|
||||
flash('Fehler beim Laden der Defekte-Items-Verwaltung.', 'error')
|
||||
app.logger.error(f"Fehler beim Laden der Ausleihen-Verwaltung: {exc}")
|
||||
flash('Fehler beim Laden der Ausleihen-Übersicht.', 'error')
|
||||
return redirect(url_for('home_admin'))
|
||||
finally:
|
||||
if client:
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<p><strong>Name:</strong> Invario UG</p>
|
||||
<p><strong>Adresse:</strong> Am Sportplatz 10<br>83052 Bruckmühl<br>Deutschland</p>
|
||||
</address>
|
||||
<p><strong>E-Mail:</strong> <a href="mailto:info@invario.eu">info@invario.eu</a></p>
|
||||
<p><strong>E-Mail:</strong> <a href="mailto:info@invario-software.de">info@invario-software.de</a></p>
|
||||
</div>
|
||||
|
||||
<div class="impressum-section mb-4">
|
||||
|
||||
@@ -122,7 +122,7 @@
|
||||
<h3>Meldung von Sicherheitslücken</h3>
|
||||
<div class="license-exception-notice">
|
||||
<h3>⚠️ Responsible Disclosure</h3>
|
||||
<p>Falls Sie eine Sicherheitslücke entdecken, wenden sie sich umgehend an die Email: info@invario.eu .
|
||||
<p>Falls Sie eine Sicherheitslücke entdecken, wenden sie sich umgehend an die Email: info@invario-software.de .
|
||||
</div>
|
||||
</div>
|
||||
</div><!-- /#pane-security -->
|
||||
|
||||
@@ -29,31 +29,12 @@ EOF
|
||||
parse_args() {
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--invoice-archive-dir)
|
||||
INVOICE_ARCHIVE_DIR="$2"
|
||||
shift 2
|
||||
;;
|
||||
--invoice-keep-days)
|
||||
KEEP_DAYS="$2"
|
||||
shift 2
|
||||
;;
|
||||
--mode)
|
||||
MODE="$2"
|
||||
shift 2
|
||||
;;
|
||||
--base-name)
|
||||
BASE_NAME="$2"
|
||||
shift 2
|
||||
;;
|
||||
-h|--help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Error: unknown option '$1'" >&2
|
||||
usage
|
||||
exit 2
|
||||
;;
|
||||
--invoice-archive-dir) INVOICE_ARCHIVE_DIR="$2"; shift 2 ;;
|
||||
--invoice-keep-days) KEEP_DAYS="$2"; shift 2 ;;
|
||||
--mode) MODE="$2"; shift 2 ;;
|
||||
--base-name) BASE_NAME="$2"; shift 2 ;;
|
||||
-h|--help) usage; exit 0 ;;
|
||||
*) echo "Error: unknown option '$1'" >&2; usage; exit 2 ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
@@ -67,70 +48,50 @@ cleanup_old_archives() {
|
||||
if [[ -n "$KEEP_DAYS" ]]; then
|
||||
find "$INVOICE_ARCHIVE_DIR" -maxdepth 1 -type f -mtime +"$KEEP_DAYS" -print -delete 2>/dev/null || true
|
||||
fi
|
||||
find "$FULL_BACKUP_DIR" -maxdepth 1 -type f -mtime +30 -print -delete 2>/dev/null || true
|
||||
# Cleanup old bundled backups (older than 30 days)
|
||||
find "$FULL_BACKUP_DIR" -maxdepth 1 -type f -name "full_backup_*.tar.gz" -mtime +30 -print -delete 2>/dev/null || true
|
||||
}
|
||||
|
||||
docker_backup() {
|
||||
if ! command -v docker >/dev/null 2>&1; then
|
||||
return 1
|
||||
fi
|
||||
if ! docker compose -f "$COMPOSE_FILE" ps -q app >/dev/null 2>&1; then
|
||||
return 1
|
||||
fi
|
||||
if ! command -v docker >/dev/null 2>&1; then return 1; fi
|
||||
|
||||
local timestamp="$(date +'%Y-%m-%d_%H-%M-%S')"
|
||||
local staging_dir="/tmp/backup_stage_$timestamp"
|
||||
|
||||
echo "[$(date +'%T')] Starting unified system backup..."
|
||||
mkdir -p "$staging_dir"
|
||||
|
||||
local timestamp
|
||||
timestamp="$(date +'%Y-%m-%d_%H-%M-%S')"
|
||||
|
||||
echo "[$(date +'%T')] Starting full system backup..."
|
||||
|
||||
# 1. Full MongoDB Dump
|
||||
# 1. MongoDB Dump (into staging)
|
||||
if docker compose -f "$COMPOSE_FILE" ps -q mongodb >/dev/null 2>&1; then
|
||||
echo "[$(date +'%T')] Creating MongoDB dump..."
|
||||
docker compose -f "$COMPOSE_FILE" exec -T mongodb mongodump --archive --gzip > "$FULL_BACKUP_DIR/full_db_${timestamp}.archive.gz"
|
||||
else
|
||||
echo "Warning: MongoDB container not found. Skipping DB dump."
|
||||
echo "[$(date +'%T')] Dumping Database..."
|
||||
docker compose -f "$COMPOSE_FILE" exec -T mongodb mongodump --archive --gzip > "$staging_dir/db.archive.gz"
|
||||
fi
|
||||
|
||||
# 2. Archive Logs
|
||||
# 2. Archive Assets (into staging)
|
||||
if [ -d "./Web/uploads" ]; then
|
||||
echo "[$(date +'%T')] Archiving assets..."
|
||||
tar -czf "$staging_dir/assets.tar.gz" -C . Web/uploads Web/thumbnails Web/previews 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# 3. Archive Logs (into staging)
|
||||
if [ -d "$LOG_DIR" ]; then
|
||||
echo "[$(date +'%T')] Archiving logs..."
|
||||
tar -czf "$FULL_BACKUP_DIR/logs_${timestamp}.tar.gz" -C "$(dirname "$LOG_DIR")" "$(basename "$LOG_DIR")"
|
||||
fi
|
||||
|
||||
# 3. Legacy Invoice Export
|
||||
local app_container
|
||||
app_container="$(docker compose -f "$COMPOSE_FILE" ps -q app | tr -d '[:space:]')"
|
||||
if [[ -n "$app_container" ]]; then
|
||||
local output_dir="/tmp/invoice_archive_${timestamp}"
|
||||
local remote_base="${output_dir}/${BASE_NAME}"
|
||||
|
||||
docker compose -f "$COMPOSE_FILE" exec -T app mkdir -p "$output_dir"
|
||||
|
||||
docker compose -f "$COMPOSE_FILE" exec -T app python3 /app/Web/modules/inventarsystem/backup_invoices.py \
|
||||
--archive-dir "$output_dir" \
|
||||
--base-name "$BASE_NAME" >/dev/null 2>&1 || true
|
||||
|
||||
if docker compose -f "$COMPOSE_FILE" exec -T app test -f "${remote_base}.jsonl"; then
|
||||
docker cp "$app_container":"${remote_base}.jsonl" "$INVOICE_ARCHIVE_DIR/"
|
||||
docker cp "$app_container":"${remote_base}.csv" "$INVOICE_ARCHIVE_DIR/"
|
||||
docker cp "$app_container":"${remote_base}.meta.json" "$INVOICE_ARCHIVE_DIR/"
|
||||
else
|
||||
echo "[$(date +'%T')] Info: No invoice records found to export."
|
||||
fi
|
||||
|
||||
docker compose -f "$COMPOSE_FILE" exec -T app rm -rf "$output_dir"
|
||||
tar -czf "$staging_dir/logs.tar.gz" -C "$(dirname "$LOG_DIR")" "$(basename "$LOG_DIR")"
|
||||
fi
|
||||
|
||||
# 4. Bundle everything into one file
|
||||
echo "[$(date +'%T')] Bundling archive..."
|
||||
tar -czf "$FULL_BACKUP_DIR/full_backup_$timestamp.tar.gz" -C "$staging_dir" .
|
||||
|
||||
# 5. Cleanup staging
|
||||
rm -rf "$staging_dir"
|
||||
|
||||
echo "[$(date +'%T')] Backup complete: $FULL_BACKUP_DIR/full_backup_$timestamp.tar.gz"
|
||||
return 0
|
||||
}
|
||||
|
||||
main() {
|
||||
parse_args "$@"
|
||||
|
||||
if [[ -z "$BASE_NAME" ]]; then
|
||||
BASE_NAME="invoices-$(date +'%Y-%m-%d_%H-%M-%S')"
|
||||
fi
|
||||
|
||||
ensure_directory
|
||||
|
||||
case "$MODE" in
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
"username": "",
|
||||
"password": "",
|
||||
"from_address": "",
|
||||
"default_sender_name": "Invario Inventurprogramm",
|
||||
"default_sender_name": "Invario Inventarprogramm",
|
||||
"timeout_seconds": 30
|
||||
},
|
||||
"images": {
|
||||
|
||||
Executable
+58
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
BACKUP_DIR="/var/backups/inventarsystem"
|
||||
COMPOSE_FILE="docker-compose-multitenant.yml"
|
||||
|
||||
# 1. Find the latest backup bundle
|
||||
LATEST_BACKUP=$(ls -t "$BACKUP_DIR"/full_backup_*.tar.gz | head -n1 2>/dev/null || true)
|
||||
|
||||
if [[ -z "$LATEST_BACKUP" ]]; then
|
||||
echo "Error: No backup bundle found in $BACKUP_DIR"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "--- RESTORE PROCEDURE ---"
|
||||
echo "Found latest bundle: $(basename "$LATEST_BACKUP")"
|
||||
read -p "WARNING: This will OVERWRITE your current database and assets! Continue? (y/N) " confirm
|
||||
[[ "$confirm" != "y" ]] && exit 1
|
||||
|
||||
# 2. Extract the bundle to a temporary location
|
||||
RESTORE_TMP="/tmp/restore_$(date +%s)"
|
||||
mkdir -p "$RESTORE_TMP"
|
||||
echo "Extracting bundle..."
|
||||
tar -xzf "$LATEST_BACKUP" -C "$RESTORE_TMP"
|
||||
|
||||
# 3. Stop application
|
||||
echo "Stopping application..."
|
||||
docker compose -f "$COMPOSE_FILE" stop app
|
||||
|
||||
# 4. Restore Database
|
||||
if [ -f "$RESTORE_TMP/db.archive.gz" ]; then
|
||||
echo "Restoring MongoDB..."
|
||||
zcat "$RESTORE_TMP/db.archive.gz" | docker compose -f "$COMPOSE_FILE" exec -T mongodb mongorestore --archive --gzip --drop
|
||||
else
|
||||
echo "Warning: Database archive not found in bundle."
|
||||
fi
|
||||
|
||||
# 5. Restore Assets
|
||||
if [ -f "$RESTORE_TMP/assets.tar.gz" ]; then
|
||||
echo "Restoring Assets (Uploads/Thumbnails/Previews)..."
|
||||
tar -xzf "$RESTORE_TMP/assets.tar.gz" -C .
|
||||
else
|
||||
echo "Warning: Asset archive not found in bundle."
|
||||
fi
|
||||
|
||||
# 6. Restore Logs (Optional)
|
||||
if [ -f "$RESTORE_TMP/logs.tar.gz" ]; then
|
||||
echo "Restoring Logs..."
|
||||
tar -xzf "$RESTORE_TMP/logs.tar.gz" -C .
|
||||
fi
|
||||
|
||||
# 7. Start application
|
||||
echo "Restarting application..."
|
||||
docker compose -f "$COMPOSE_FILE" start app
|
||||
|
||||
# 8. Cleanup
|
||||
rm -rf "$RESTORE_TMP"
|
||||
echo "Restore complete!"
|
||||
Reference in New Issue
Block a user