r2
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
# Weekly uploads rsync backup — call via cron
|
||||
# crontab: 0 2 * * 0 /home/ubuntu/site/scripts/backup-uploads.sh >> /var/log/vitfit-uploads-backup.log 2>&1
|
||||
|
||||
set -e
|
||||
|
||||
source "$(dirname "$0")/../.env" 2>/dev/null || true
|
||||
|
||||
UPLOADS_DIR="${UPLOADS_DIR:-/home/ubuntu/site/uploads}"
|
||||
BACKUP_UPLOADS_DEST="${BACKUP_UPLOADS_DEST:-/mnt/backup/uploads}"
|
||||
|
||||
if [ -z "$BACKUP_UPLOADS_DEST" ]; then
|
||||
echo "[$(date)] BACKUP_UPLOADS_DEST not set — skipping uploads backup"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
mkdir -p "$BACKUP_UPLOADS_DEST"
|
||||
|
||||
rsync -av --checksum "$UPLOADS_DIR/" "$BACKUP_UPLOADS_DEST/"
|
||||
echo "[$(date)] Uploads backup complete: $UPLOADS_DIR → $BACKUP_UPLOADS_DEST"
|
||||
@@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
# SQLite daily backup — call via cron
|
||||
# crontab: 0 3 * * * /home/ubuntu/site/scripts/backup.sh >> /var/log/vitfit-backup.log 2>&1
|
||||
|
||||
set -e
|
||||
|
||||
source "$(dirname "$0")/../.env" 2>/dev/null || true
|
||||
|
||||
DB_PATH="${DB_PATH:-/home/ubuntu/site/database.sqlite}"
|
||||
BACKUP_DIR="${BACKUP_DIR:-/home/ubuntu/backups}"
|
||||
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
|
||||
BACKUP_FILE="$BACKUP_DIR/vitfit_$TIMESTAMP.sqlite"
|
||||
|
||||
mkdir -p "$BACKUP_DIR"
|
||||
|
||||
sqlite3 "$DB_PATH" ".backup '$BACKUP_FILE'"
|
||||
echo "[$(date)] Backup created: $BACKUP_FILE"
|
||||
|
||||
# Remove backups older than 14 days
|
||||
find "$BACKUP_DIR" -name "vitfit_*.sqlite" -mtime +14 -delete
|
||||
echo "[$(date)] Old backups purged"
|
||||
@@ -0,0 +1,90 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
|
||||
require('dotenv').config({ path: require('path').join(__dirname, '..', '.env') });
|
||||
|
||||
const readline = require('readline');
|
||||
const bcrypt = require('bcryptjs');
|
||||
|
||||
const rl = rl_create();
|
||||
|
||||
function rl_create() {
|
||||
return readline.createInterface({ input: process.stdin, output: process.stdout });
|
||||
}
|
||||
|
||||
function ask(question) {
|
||||
return new Promise(resolve => rl.question(question, resolve));
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log('\nVitFit V2 — First-Time Setup\n');
|
||||
|
||||
const { initDb, runMigrations, models } = require('../core/db');
|
||||
|
||||
await initDb();
|
||||
await runMigrations();
|
||||
|
||||
// Refuse if any org exists
|
||||
const orgCount = await models.Organization.count();
|
||||
if (orgCount > 0) {
|
||||
console.error('ERROR: An organization already exists. Setup can only run on a fresh install.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const orgName = await ask('Organization name (e.g. CrossFit Downtown): ');
|
||||
const timezone = await ask('Timezone (e.g. America/New_York) [UTC]: ') || 'UTC';
|
||||
const ownerUser = await ask('Owner username: ');
|
||||
const ownerPass = await ask('Owner password (min 8 chars): ');
|
||||
const ownerEmail = await ask('Owner email (optional): ');
|
||||
const saUser = await ask('SystemAdmin username: ');
|
||||
const saPass = await ask('SystemAdmin password (min 8 chars): ');
|
||||
|
||||
rl.close();
|
||||
|
||||
if (ownerPass.length < 8 || saPass.length < 8) {
|
||||
console.error('ERROR: Passwords must be at least 8 characters.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const { sequelize } = require('../core/db');
|
||||
const transaction = await sequelize.transaction();
|
||||
|
||||
try {
|
||||
const org = await models.Organization.create({ name: orgName, timezone }, { transaction });
|
||||
await models.Branding.create({ organizationId: org.id }, { transaction });
|
||||
|
||||
const ownerHash = await bcrypt.hash(ownerPass, 12);
|
||||
await models.User.create({
|
||||
organizationId: org.id,
|
||||
username: ownerUser,
|
||||
email: ownerEmail || null,
|
||||
password: ownerHash,
|
||||
role: 'Owner',
|
||||
isActive: true,
|
||||
}, { transaction });
|
||||
|
||||
const saHash = await bcrypt.hash(saPass, 12);
|
||||
await models.User.create({
|
||||
organizationId: null,
|
||||
username: saUser,
|
||||
password: saHash,
|
||||
role: 'SystemAdmin',
|
||||
isActive: true,
|
||||
}, { transaction });
|
||||
|
||||
await transaction.commit();
|
||||
|
||||
console.log('\n✓ Setup complete.');
|
||||
console.log(` Organization: ${orgName} (id: ${org.id})`);
|
||||
console.log(` Owner: ${ownerUser}`);
|
||||
console.log(` SystemAdmin: ${saUser}`);
|
||||
console.log('\nStart the app with: npm start\n');
|
||||
process.exit(0);
|
||||
} catch (err) {
|
||||
await transaction.rollback();
|
||||
console.error('Setup failed:', err.message);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main().catch(err => { console.error(err); process.exit(1); });
|
||||
Reference in New Issue
Block a user