Skip to content

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

License

maxdorx/server-backup-scripts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Linux Server Backup Scripts

Bash scripts that snapshot app data and databases, then transfer archives to a remote server over SSH/scp. Designed for Linux hosts but can back up from any environment where these services run.

Included

  • NGINX config snapshot
  • Orion-Assets static assets
  • SQL Server data-directory archive
  • PostgreSQL logical dump (pg_dumpall)
  • MongoDB dump from container
  • Core-Fabric stack archive
  • Consolidated Mongo dev stack archiver

Requirements

  • Linux host with Bash, tar, gzip, scp
  • Docker (for container-based services)
  • Remote server with OpenSSH enabled
  • .env populated from sample.env

Quick start

cp sample.env .env
chmod +x scripts/*.sh
# test one component
env $(cat .env | xargs) scripts/postgres-backup.sh

Usage

# NGINX
env $(cat .env | xargs) scripts/nginx-backup.sh /etc/nginx/nginx.conf

# Orion-Assets
env $(cat .env | xargs) scripts/orion-assets-backup.sh

# SQL Server
env $(cat .env | xargs) scripts/sqlserver-backup.sh

# PostgreSQL
env $(cat .env | xargs) scripts/postgres-backup.sh

# Mongo (single container)
env $(cat .env | xargs) scripts/mongo-backup.sh

# Core-Fabric tree
env $(cat .env | xargs) scripts/core-fabric-backup.sh

# Mongo dev stacks (pass directory name under $PERSIST_ROOT)
env $(cat .env | xargs) scripts/mongo-dev-backup.sh mongo_dev
env $(cat .env | xargs) scripts/mongo-dev-backup.sh mongo_dev_1

Scheduling

crontab -e
# run nightly at 01:30
30 1 * * * cd /opt/linux-backup-scripts && \
  env $(cat .env | xargs) bash scripts/postgres-backup.sh \
  >/var/log/pg-backup.cron 2>&1

Restore cheat sheet

  • PostgreSQL:
    gunzip -c postgres-*.sql.gz | psql -U postgres
  • MongoDB:
    tar -xzf mongodb_*.tar.gz && mongorestore dump/
  • File archives:
    tar -xzf backup.tar.gz -C <target_dir>
  • NGINX conf:
    cp backup-nginx.conf /etc/nginx/nginx.conf
    nginx -t && systemctl reload nginx

Security

  • Keep .env out of Git.
  • Use a least-privileged SSH account and key authentication.
  • Restrict scp destination directories on the remote server.

⚠️ Note: All IPs, usernames, ports, and paths shown here are placeholders. Replace them with values from your own environment before running the scripts.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages