Backups!
Well now that I have a couple of applications and servers up and running that I am finding useful to keep around I need to back them up. At least the applications data. For the existing Windows servers is my testing lab I have them backing up to the Veeam Community Edition, but with this version of Veeam, the limitations are going to prevent me from just being able to back up the virtual machines.
As I think about this I start to wonder if I really need to backup the virtual machines? It's quick and easy to spin up a Linux virtual machine, and with my notes on installing each application that would make it really quick and easy to bring them back online. Let's be honest, this isn't a production environment so if something crashes I'm the only person impacted and would be able to fix things at my leisure.
With that said backups are always important no matter what, and even if I just have a backup of application data that would certainly speed up the restoration quite a bit. Most applications have a built in backup or export function right in the GUI itself, but I can assure you I will never be able to make a habit out of going into all those GUIs on a regular basis to make backups. This needs to be automated to where all I need to do is make sure the backup files have been created.
This would be a good exercise to practice a little bit of scripting. If I setup a script on each of my Linux virtual machines to create a backup of it's application, I could then mount a connection to my fileserver and store a copy of the backup there, giving me a second location. If I ever start viewing any of these applications as critical I could at that point then make a third copy offsite by a cloud service. Say iCloud or OneDrive would probably suffice.
I'm going to start with Pi-Hole. I love it, they have a command to create a backup. This will make things simple. I log into Github and create a pihole-backup.sh
file.
#!/bin/bash
### Backup script for Pi-Hole
# Move to the backup directory
cd /home/david/Backups/Pi-Hole
# Create a backup file
pihole -a -t
# Copy backup file to fileserver
rsync -avh /home/david/Backups/Pi-Hole/ /mnt/Backups/Server/PH-01/
Now let's work this out step by step on PH-01.
Steps performed on PH-01
mkdir /home/david/Backups
mkdir /home/david/Backups/Pi-Hole
sudo mkdir /mnt/Backups
cd /home/david/Backups/Pi-Hole
pihole -a -t
ls
pi-hole-PH-01-teleporter_2022-08-28_13-02-01.tar.gz
Cool, now I just need to get the mount working.
Steps performed on DC-02 via Windows Admin Center
- I navigate to
Active Directory
- I move to
Browse
- I click on
Managed Service Accounts
OU - I click on
Add
and thenUser
- Name:
_service_backups
- Sam Account Name:
_service_backups
- Password:
- Given Name:
Backup Service
- I click on
Change...
- I select the
Managed Service Accounts
path - I hit
Select
- I verify the Create in:
CN=Managed Service Accounts
DC=domain
DC=local
- I click on
Create
- Name:
- I select
_service_backups
- I click on
Enable
I wish Windows Admin Center'sActive Directory
option had access to all the properties. It's always fun seeing Microsoft abandon these tools before they even finish them. Well since the account has been created I pop over to my fileserver and give_service_backups
access to a folder where backup files can be dumped.
Steps performed on PH-01
I wish Windows Admin Center's Active Directory
option had access to all the properties. It's always fun seeing Microsoft abandon these tools before they even finish them. Well since the account has been created I pop over to my fileserver and give _service_backups
access to a folder where backup files can be dumped.
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
fstab
Oh I'm glad I thought of it, I need to install cifs-utils
.
sudo apt install cifs-utils
sudo reboot
ls /mnt/Backups
Applications Servers
Success! A test of rsync -avh /home/david/Backups/Pi-Hole/ /mnt/Backups/Server/PH-01/
is also successful. So my last step becomes creating the script itself.
sudo nano /usr/bin/pihole-backup
#!/bin/bash
# Backup script for Pi-Hole
# Move to backup directory
cd /home/david/Backups/Pi-Hole
# Create backup file
pihole -a -t
# Copy backup file to fileserver
rsync -avh /home/david/Backups/Pi-Hole/ /mnt/Backups/Servers/PH-01/
- I save
pihole-backup
sudo chmod +x /usr/bin/pihole-backup
sudo nano /etc/crontab
# Run backup script for Pi-Hole
2 3 * * 5 root /usr/bin/pihole-backup
- I save the file
crontab
So that will give me a backup every Thursday morning. So I'll be able to check on it Thursday and if there is any problems I'll have the weekend where I usually have some more time available to look at it and fix it. Cool, now I just have to do the exact same thing for PH-02. Then tomorrow I can work on tackle the other services.