NGINX Reverse Proxy, Part Five

NGINX Reverse Proxy, Part Five
Photo by Roman Synkevych / Unsplash

So with NGINX working it's time to back it up. Should be simple enough to do, I just need to grab some configuration files and put them all together. So I'll work up a draft in Github named nginx-proxy-backup.sh:

#!/bin/bash

### Backup script for Nginx
## This script will make a backup of the Nginx configuration

# Create a backup of the nginx.conf file
cp /etc/nginx/nginx.conf /home/david/Backups/nginx/nginx-`date +%F`.conf

# Create a backup of the proxy.conf file
cp /etc/nginx/sites-available/proxy.conf /home/david/Backups/nginx/proxy-`date +%F`.conf

# Create a backup of the Fail2Ban jail.conf file
cp /etc/fail2ban/jail.local /home/david/Backups/nginx/jail.local-`date +%F`.conf

# Compress and archive all files
tar -czvf /home/david/Backups/nginx/Archive/nginx-proxy-backup-`date +%F`.tar.gz /home/david/Backups/nginx/nginx-`date +%F`.conf /home/david/Backups/nginx/proxy-`date +%F`.conf /home/david/Backups/nginx/jail.local-`date +%F`.conf

# Remove all temporary files
rm -rf /home/david/Backups/nginx/nginx-`date +%F`.conf /home/david/Backups/nginx/proxy-`date +%F`.conf /home/david/Backups/nginx/jail.local-`date +%F`.conf

# Copy backup to fileserver
rsync -avh /home/david/Backups/nginx/Archive/ /mnt/Backups/domain.local/Servers/NGINX-01/

Steps performed on NGINX-01

  • mkdir /home/david/Backups
  • mkdir /home/david/Backups/nginx
  • sudo mkdir /mnt/Backups
  • mkdir /home/david/.win
  • nano /home/david/.win/_service_backups-credentials
username=_service_backups
password=
domain=domain.local
  • I save the _service_backups-credentials file
  • chmod 600 /home/david/.win/_service_backups-credentials
  • sudo nano /etc/fstab
# Mount for backing up to fileserver
//10.10.10.XXX/Data/Files/Backups/domain.local /mnt/Backups cifs credentials=/home/david/.win/_service_backups-credentials,uid=1000,gid=1000,iocharset=utf8
  • I save the fstab file
  • sudo apt install cifs-utils
  • sudo reboot
  • ls /mnt/Backups
    • Applications Servers
  • sudo nano /usr/bin/nginx-proxy-backup
#!/bin/bash

### Backup script for Nginx
## This script will make a backup of the Nginx configuration

# Create a backup of the nginx.conf file
cp /etc/nginx/nginx.conf /home/david/Backups/nginx/nginx-`date +%F`.conf

# Create a backup of the proxy.conf file
cp /etc/nginx/sites-available/proxy.conf /home/david/Backups/nginx/proxy-`date +%F`.conf

# Create a backup of the Fail2Ban jail.conf file
cp /etc/fail2ban/jail.local /home/david/Backups/nginx/jail.local-`date +%F`.conf

# Compress and archive all files
tar -czvf /home/david/Backups/nginx/Archive/nginx-proxy-backup-`date +%F`.tar.gz /home/david/Backups/nginx/nginx-`date +%F`.conf /home/david/Backups/nginx/proxy-`date +%F`.conf /home/david/Backups/nginx/jail.local-`date +%F`.conf

# Remove all temporary files
rm -rf /home/david/Backups/nginx/nginx-`date +%F`.conf /home/david/Backups/nginx/proxy-`date +%F`.conf /home/david/Backups/nginx/jail.local-`date +%F`.conf

# Copy backup to fileserver
rsync -avh /home/david/Backups/nginx/Archive/ /mnt/Backups/domain.local/Servers/NGINX-01/
  • I save nginx-proxy-backup
  • sudo chmod +x /usr/bin/nginx-proxy-backup
  • sudo nano /etc/crontab
# Run backup script for Pi-Hole
21 3 * * 5 root /usr/bin/nginx-proxy-backup.sh

That will give me a backup early in the morning every Thursday. That way if there are any problems creating the backup I can work on it over the weekend, when I have more time to tackle a problem like that.