I have a media server (Debian) and a remote storage backup server (rocky 9 with NFS setup). Everything works fine, but I have an unavoidable situation that may cause some issues and I would like to seek opinions from here.
According to some documentation, I can make a local share file like so.
On rocky server, install NFS, create a directory (e.g /mymedia/backup) and share it through the network.
On Debian server, create a directory (e.g /home/user/backup-directory), and then mount the rocky share file to the directory created earlier.
To make an automated daily backup, I use rsync and crontab and set it to do full/partial backup every 12am.
The problem is, sudden power outages often happen at the remote backup site and causing connection breakage between the 2 servers. Assuming there is a power outage right at 12am and the Debian is going to backup the media, it will cause the Debian to “recopy” everything into its own local drive since the directory as mentioned earlier is not mounted to the backup site. Is there a way like to make the debian server to check if the rocky server is ready/not ready before backing up data?
Sorry for the long story and your help is highly appreciated.
I would look at using something like Restic that can handle all the backup logic for you (mounting / unmounting the destination, doing backups as necessary, ignoring backup tasks when already completed, etc).
Sorry, I did the annoying thing of ignoring the question you directly asked, in favor of trying to address your overall backup problem. If you want to keep using your current system, I suppose you could just add a line to your script that checks if the directory is mounted to the right fs, using findmnt.
Don’t worry about it. In fact I would love to hear more opinions to learn more stuff. But for now, I still can’t try the solutions you have given. I’ll update you once I’ve done testing your ideas. Thanks a lot.
The noauto,nofail basically say that system can boot without mounting the share.
The x-systemd.automount,x-systemd.idle-timeout=300 tell systemd to create an automount unit on boot that will watch the /home/user/backup-directory. Whenever some process tries to use that directory, it is mounted from the rocky server, and if it is not used for 5 minutes (300 sec), then it is automatically unmounted.
That way the rsync makes the system (re)mount the share “on need”, and most of the time the share remains not mounted. (Not completely sure how the mount goes if the server is inaccessible.)
If systemd can’t do that in Debian, there should be at least autofs for the same purpose.
For backup, you can use rsync to backup your data without using nfs mount at all. Set up rsync server on the Debian server(open port 873), and do the backup on Rocky server. If the connection is broken(like power outage, network disconnected), backup just fails. Also you can set up the incremental backup after rsync with “/bin/cp -RlpP” to a new folder daily.