
Bash scripts for automated backups of NGINX, SQL Server, PostgreSQL, MongoDB, and other services from Linux hosts to a remote server over SSH/SCP.

In our environment, we already had Azure cloud backups enabled for business continuity. But the team wanted nightly local copies as an extra safety net. The requirement was simple: every night, the latest configs and data should also land on our Windows server in the office.
I decided to build a lightweight, script-driven solution for this. No extra licensing, no heavy agents ā just plain Bash and scp.
pg_dumpall)Each archive is timestamped and shipped via scp to D:/Backups/... on the Windows host.
These jobs run every night via cron, so by morning, both Azure and local copies are available.
.tar.gz or .sql.gz.Full repo: linux-backup-scripts
linux-backup-scripts/
āā scripts/
ā āā nginx-backup.sh
ā āā sqlserver-backup.sh
ā āā postgres-backup.sh
ā āā mongo-backup.sh
ā āā core-fabric-backup.sh
ā āā mongo-dev-backup.sh
āā sample.env
āā README.md
āā LICENSE
āā .gitignorescp -P $REMOTE_PORT $tmp/${stamp}-nginx.conf ${REMOTE_USER}@${REMOTE_HOST}:$DEST_DIRThis takes /etc/nginx/nginx.conf, stamps it with the date, and sends it to the Windows path.
pg_dumpall ā gzip ā transfermongodump inside container ā copy out ā tar ā transferEach writes to its own log under /var/backups.
# Postgres backup nightly at 2:00
0 2 * * * cd /opt/linux-backup-scripts && env $(cat .env | xargs) scripts/postgres-backup.sh >>/var/log/postgres-backup.cron 2>&1This is how they ran every night without fail.
gunzip -c postgres-YYYYMMDD.sql.gz | psql -U postgrestar -xzf mongodb_*.tar.gz
mongorestore dump/tar -xzf backup.tar.gz -C /restore/path.env is ignored in Git.svc-backup is least-privileged.scp with rsync for speed and delta sync.I used these scripts on our Azure Linux servers and send backups to our on-prem Windows server every night via SSH/SCP.
ā ļø Note: All IPs, usernames, ports, and paths shown here are placeholders. Replace them with values from your own environment before running the scripts.