1.9 KiB
1.9 KiB
Ubuntu Server 1.2: Automated remote backups
A backup of /etc to another machine with rsync over SSH, as a user other
than root, a nightly systemd timer, and a restore that keeps owners.
Before you start
The peer, at 10.99.0.2 (name peer), is the backup server, s2. It runs
its own sshd, and shares this VM's users and files: an account you create
here exists there too, and the peer's /srv/backups is this VM's. Reach it
with ssh peer; get a shell in its network with sudo ip netns exec lepeer bash.
The lab writes an /etc/motd for task 3; look at its owner and mode with
ls -l /etc/motd before you start.
Tasks
- As root, back up
/etcto/srv/backups/s1-etc/on the peer as a userbkp(not root), using rsync over SSH with a dedicated key,/root/.ssh/backup_key.sudo rsync -avn --delete -M--fake-super -e "ssh -i /root/.ssh/backup_key" /etc/ bkp@peer:/srv/backups/s1-etc/lists no files to send and ends with(DRY RUN). - Run that backup every day at 1:15 am with a systemd timer that catches
up after downtime.
systemctl list-timersshows your timer with the next run at 01:15 (plus any random delay);sudo systemctl startof the service ends with "Finished" in its journal. - Delete
/etc/motd, then restore it from the peer. After the restore,ls -l /etc/motdshows the file with its original owner and mode.
Hints
ssh-keygen -N "" -f /root/.ssh/backup_key;useradd -m,install -d -o bkp -g bkp,~bkp/.ssh/authorized_keys. Connect once by hand with-o StrictHostKeyChecking=accept-newso the host key is known.rsync -a --delete -M--fake-super -e "ssh -i KEY -o BatchMode=yes": the trailing slash on/etc/matters.- A
Type=oneshotservice and a.timerwithOnCalendar=,Persistent=true; enable the timer.systemd-analyze calendar,systemctl list-timers,journalctl -u. - The same rsync the other way, with
-M--fake-super.