Skip to content

Daily Operations

# /var/spool/cron/ancora (or /etc/cron.d/ancora)
30 23 * * * ancora /home/ancora/scripturi/daily_job.sh

Runs every night at 23:30 as the ancora user.


flowchart TD
    START(["23:30 — cron triggers\ndaily_job.sh"])

    A["1. Fetch BNR exchange rates\nwget https://bnr.ro/nbrfxrates.xml\nParse XML → call cursbnr00.jsp\nUpdates cursvalutarbnr in ALL tenant DBs"]

    B["2. Generate daily reports\nPOST /ancoraerp/daily_reports.serv\nBuilds HTML sales/stock summary\nAttempts email to disponibilul@gmail.com"]

    C["3. Read tenant list\nSELECT bazadate FROM public.unitati\nWHERE inactiv=false AND isbackup=false"]

    D["4. For each tenant DB in list…"]

    E["4a. vacuumdb --freeze --analyze\n(prevents XID wraparound,\nupdates query planner stats)"]

    F["4b. pg_dump -Fc\nDump to /home/ancora/backup/\$(date +%%u)/\${dbname}.dump\n(overwrites same weekday slot from last week)"]

    G["4c. auto_actdb.serv\nApply any pending SQL migration scripts\n(1493 scripts total as of mid-2025)"]

    H["5. Restart PostgreSQL service\nsystemctl restart postgresql-11\n(ensures clean connection pool)"]

    I["6. Send summary email\nBuilds HTML report of backup sizes,\nmigration results, errors\nSMTP: 192.168.0.105:25 (primary)\nSMTP: smtp.gmail.com:465 (fallback)"]

    ERR["⚠ Both SMTP servers currently\nunreachable — emails silently fail"]

    DONE(["Done — sleep until 23:30 next night"])

    START --> A --> B --> C --> D
    D --> E --> F --> G
    G -->|next tenant| D
    D -->|all tenants done| H --> I
    I -->|delivery failure| ERR
    I --> DONE
    ERR --> DONE

/home/ancora/backup/
├── 1/ ← Monday
│ ├── maxx.dump # ~418 MB compressed
│ └── maxx_suport.dump # ~87 MB compressed
├── 2/ ← Tuesday
│ └── ...
├── 3/ ← Wednesday
│ └── ...
├── 4/ ← Thursday
│ └── ...
├── 5/ ← Friday
│ └── ...
├── 6/ ← Saturday
│ └── ...
└── 7/ ← Sunday
└── ...
  • Slot key: $(date +%u) — ISO day-of-week (1=Mon, 7=Sun)
  • Retention: 7 rolling days (previous week’s same-day file is overwritten)
  • Format: pg_dump -Fc (custom compressed, not plain SQL)
  • Restore: pg_restore -d targetdb backup/3/maxx.dump
  • No off-site sync detected — backups exist on the same machine

Called once per tenant DB per night. Keeps every tenant DB in sync with the latest schema version deployed in actualizaredb/.

sequenceDiagram
    participant SH as daily_job.sh
    participant TC as Tomcat
    participant SVC as DarkAutomaticActualizare
    participant FS as /actualizaredb/*.sql
    participant PG as Tenant PostgreSQL DB

    SH->>TC: wget http://localhost:8080/ancoraerp/auto_actdb.serv?db_email=maxx&email=...
    TC->>SVC: BasicServicesController dispatches

    SVC->>PG: SELECT COALESCE(MAX(nr_actualizare),0) FROM setari_actualizare
    PG-->>SVC: current = 1480

    SVC->>FS: list files 1481.sql … 1493.sql
    loop for each pending file
        SVC->>PG: execute SQL from file N.sql
        SVC->>PG: INSERT INTO setari_actualizare(nr_actualizare, data) VALUES(N, NOW())
    end

    SVC-->>SH: HTML: "Applied 13 updates successfully"

There is no active monitoring stack detected:

ComponentStatus
Nagios / Zabbix / PrometheusNot installed
Log rotationlogrotate.conf present (standard CentOS)
Tomcat logs/opt/tomcat/logs/catalina.out (unbounded)
Disk usage alertsNone
Backup verificationNone (no test-restore process)
Email alertsConfigured but SMTP broken
AnyDeskInstalled — remote access for manual troubleshooting

Software updates arrive via the maxx user account or direct Tomcat WAR replacement:

flowchart LR
    VENDOR["ancora.ro vendor"] -->|"SCP / manual upload\nor Tomcat manager"| TOMCAT["Tomcat webapps/\nancoraerp/"]
    TOMCAT -->|"JARs in WEB-INF/lib/"| NEWJARS["Updated business JARs\n(ancora-mailer.jar,\naprovizionare.jar, etc.)"]
    TOMCAT -->|"actualizaredb/NNNN.sql"| SQLSCRIPTS["New DB migration scripts"]
    SQLSCRIPTS -->|"next auto_actdb.serv run"| ALLTENANTS["Applied to all tenant DBs\nautomatically next night"]

The cale_dark_cloud parameter (http://82.77.60.34:9999/) points to a central Ancora server — this is used for:

  • License key verification
  • D394 fiscal declaration processing (Romanian VAT return)
  • Possibly pushing WAR/JAR updates (unconfirmed)