0

Background: Pi-4 running Buster configured with Postfix and dovecot serving several domains. It is working fine.

I would like to set up a second Pi as a backup. I already have a process to backup the e-mail folders and the SQL files, but that requires some hands-on work to recover from a disaster. The second Pi is on the same internal network (intranet), almost side-by-side.

My question: is there a way to clone to WHOLE thing from the active Pi to the backup Pi in real time, for example every 12 hours? Then if disaster strikes all we have to do is update the router with a new address for e-mail.

Thanks...RDK45

2 Answers 2

1

Cloning the whole system on-line may be inefficient and might cause unexpected problems. For example:

  • if you are using their announced hostnames to connect to them, they will now be identical
  • if a program created a temporary file for itself, it would not be deleted (since there would be no process on the new machine that remembers it should be)

The more appropriate approach would be to install the same OS and software on the second Pi and then copy over the relevant folders using rsync. You could set up a cron job for scheduled runs.

4
  • Generally speaking applications which create and use temporary files do it in one of a few conventional locations (/tmp or /run), making them easy to exclude (eg. via rsync --exclude-from=list.txt).
    – goldilocks
    Sep 6, 2023 at 14:15
  • @goldilocks A famous counterexample is nano, which creates a .filename.swp file in the same place you're editing the file. Though in this case it only contains metadata about who is editing the file, still, its presence may lead to some confusion when one later tries to open some file and nano tells it's already open by someone. It's better to sync only what is necessary to minimize the amount of such cases.
    – 5anya
    Sep 6, 2023 at 14:29
  • Probably a misnomer to call that a counter-example as it's common for editors to do that -- I meant more in relation to background services and not interactive apps; after all it is a mail server. This is something the OP needs to take into account but isn't really a deal breaker. However, I agree with you that the better approach is to determine what data and configuration is used by the mail server software and then maintain an identically outfitted Pi just syncing that data and config stuff, not the whole root fs.
    – goldilocks
    Sep 6, 2023 at 16:09
  • OK, thanks. Now I guess I need to study rsync to see how it works (code and practice) and also determine exactly which files and folders need to be copied to the backup Pi. I know that the mail folders for each domain and the SQL files need to be transferred. I will investigate if there are others.
    – RDK
    Sep 6, 2023 at 20:42
0

It is not clear exactly what you want to do.

There are programs which backup running Pi and create an image - search this site for details.

The Pi has a SD Card copier which will copy a running system.

You could use rsync to sync a master system to another.

All of these suffer from the same problem. Based on 50 years experience and established practice any system based on a single backup is just going you a false sense of security.

Any automated backup risks copying any errors.

You need a proper system to make multiple backups and a process to rotate them.


Some time ago I wrote a rsync script to keep my Pi in sync. I haven't used in years but it may provide some guidelines. It makes assumptions e.g. user pi so will need tweaking.

#!/bin/bash
# script to synchronise current Pi from remote.
# Does not DELETE unmatched files
# 2017-04-10
# 2020-04-30

CURRENT_HOSTNAME=$(cat /etc/hostname)
echo "Current Name" $CURRENT_HOSTNAME

REMOTE_HOSTNAME="MilliwaysPi4.local"
echo "Remote Name" $REMOTE_HOSTNAME

# Resolve .local address
RemotePi=$(getent hosts $REMOTE_HOSTNAME | awk '{ print $1 }')

if [ $RemotePi ]; then
    echo $RemotePi
    echo "Commencing Copy"
#         -a        archive mode; equals -rlptgoD (no -H,-A,-X)
#         -H        preserve hard links
#         -u        skip files that are newer on the receiver
    sudo rsync -aHu --exclude-from=rsync-dup-exclude.txt --exclude='/SD?' --exclude='/SD??'  pi@$RemotePi:/ /
else
    echo "RemotePi not available"
fi

This uses rsync-dup-exclude.txt to exclude unwanted stuff.

/proc/*
/sys/*
/dev/*
/boot/*
/tmp/*
/run/*
/mnt/*/*
/var/cache/*

/boot/cmdline.txt
/etc/fstab

.Trashes
._.Trashes
.fseventsd
.Spotlight-V100
.DS_Store
.AppleDesktop
.AppleDB
Network Trash Folder
Temporary Items

.cache
/etc/fake-hwclock.data
/var/lib/rpimonitor/stat/
/etc/hostname
/etc/hosts

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.