Hi everyone,
I’ve been playing around with the TrueNAS GUI replication and rsync tasks quite a bit lately. I’m trying to create a backup/devtest TrueNAS Server. This means that I’m not only trying create a backup, but I’m also trying to make a 2nd instance of my TrueNAS server that is able to run simultaniously with my master TrueNAS server (so it is not an exact copy, but it is very similar - it has a different name, IP, a additional Plex instance with a duplicated DB/metadata/etc).
From my testing I’ve learned a couple things that are relevant for what I’m trying to do:
- Rsync can’t properly copy ACLs. This makes it unsuitable for copying my SMB shares.
- ZFS replication requires to have snapshots. Not all my SMB shares are suitable to have many snapshots though, as some have frequently changing contents for which I only need the latest state.
- The TrueNAS GUI Data Protection options seems only designed for scheduled tasks. My TrueNAS backup/devtest server will be powered off most of the time, so scheduling backup tasks is not practical…
- If the server is already powered off before a scheduled task, this task is not picked up when the server is powered on after the scheduled task should have run.
- If the server is powered off during a scheduled task, the task is not resumed when powering the server on again.
- Running many replication tasks manually (without a schedule) is possible, but requires starting them one by one sequentially, as TrueNAS GUI does them all in parallel if you start them all at once. So, especially with mechanical HDDs, this is not really an option either.
So, as I understand it, the GUI doesn’t really offer what I’m looking for…
What I’m trying to do is not very hard to do however using a simple bash script. I already found an example script that I can use with some minor modifications:
This script is meant to do zfs replication to an external HDD, but I can easily modify it to replicate to another server as well…
What the script does is:
- Check if the the backup location already has been backed up to.
- If not then create a snapshot with findable name and zfs replicate this newly created snapshot to the backup location (initial full backup)
- If there already was a previous backup on the backup location
- then the script will find this because it has the snapshot with the findable name
- This same snapshot should then also still exist on the source location
- A new snapshot will then be created on the source (also with a findable name) and this new snapshot will be replicated (incremental) to the backup server
- Both source and backup now have 2 snapshots (old and new) and the script will then remove the oldest snapshot on both source and backup server
This way both locations only have the minimal amount of snapshots to have a working zfs incremental replication and it is possible to do an on demand backup of the current state of the filesystem with ACLs and everything…
If I feel like it, I can also easily script it to be used as a cronjob or on-init-job to for example check once per day (or on-init) if a backup was missed or is incomplete and needs resuming.
So that is all the background information and here come my actual questions
I know that TrueNAS is meant as an appliance, so modifying is to be avoided if possible and if unavoidable, then it should be done with care, hence my questions…
Not all OS files and folders customizations are “persistent” after reboots or upgrades. However, I don’t know the specifics of this, so I wonder:
Is ‘/root/bin’ a good location to store my scripts? Or will it be removed after an upgrade / reboot? Or which location do you suggest for a root script? My root homedir is the default ‘/root’.
I’ve also read that it is not advised to use the GUI created SSH keypairs outside the GUI. Is this true?
If true, then should I create them manually like on a non-appliance Linux server in /root/.ssh? Is this persistent after an upgrade / reboot? Or is there another way I should do this?
If not true, then how do I use the GUI created SSH keypairs in command line? With a ‘ps-ef’ during an rsync, I noticed that it seems like they’re using temporary keyfiles in /tmp. So I’m not sure how to use those in a script…
Also if you have any other advice / comment on how to handle this, please let me know.
Thanks!