From 3bd8fbc51140ef308a2ba04dcfb3a0cd50a63368 Mon Sep 17 00:00:00 2001 From: Janek Bevendorff Date: Mon, 6 Oct 2014 01:52:59 +0200 Subject: [PATCH] Create (commented) mount options in /etc/fstab automatically --- README.md | 26 +++++++++++++------------- install.sh | 16 ++++++++++++++++ server/etc/fstab | 7 +++++++ server/etc/fstab_synology | 8 ++++++++ server/etc/fstab_ubuntu | 7 +++++++ 5 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 server/etc/fstab create mode 100644 server/etc/fstab_synology create mode 100644 server/etc/fstab_ubuntu diff --git a/README.md b/README.md index cdd6af7..0f3ea31 100644 --- a/README.md +++ b/README.md @@ -45,25 +45,25 @@ The optional third parameter specifies the path to the SSH public key file which **TIP:** If you don't remember the parameters for all these commands, simply run them without any and you'll get simple usage instructions. #### Making the chroot work -rs-backup-suite can chroot backup users into the backup home base directory. For this to work you need to add a few lines to your `/etc/fstab` and run `mount -a` afterwards (replace `/bkp` with your backup path): +rs-backup-suite can chroot backup users into the backup home base directory. For this to work you need to create a few bind mounts. The install script already created the respective lines in your `/etc/fstab` for you. If you don't need any special configuration on your system, all you need to do is to uncomment everything between the `BEGIN` and `END` lines (do NOT change these two lines, though): - # Chroot - /bin /bkp/bin none bind 0 0 - /lib /bkp/lib none bind 0 0 - /usr/bin /bkp/usr/bin none bind 0 0 - /usr/lib /bkp/usr/lib none bind 0 0 - /usr/share/perl5 /bkp/usr/share/perl5 none bind 0 0 - /dev /bkp/dev none bind 0 0 + # BEGIN: rs-backup-suite + #/lib /bkp/lib none bind 0 0 + #/dev /bkp/dev none bind 0 0 + #/usr/bin /bkp/usr/bin none bind 0 0 + #/usr/lib /bkp/usr/lib none bind 0 0 + #/usr/share/perl5 /bkp/usr/share/perl5 none bind 0 0 + # END: rs-backup-suite -**NOTE:** In Ubuntu the Perl modules are located at `/usr/share/perl` instead of `/usr/share/perl5`. Change that accordingly. Also note that if you are using Synology DSM, you also need to add a bind mount for /opt/bin to /bkp/opt/bin. +The necessary mounts may differ from system to system. For instance, Ubuntu needs `/usr/share/perl` instead of `/usr/share/perl5`. Synology DSM doesn't need `/usr/share/*` at all, but requires `/opt/bin`, `/opt/lib` and `/opt/libexec`. But in most cases you don't need to worry about that since the install script tries to make the correct decisions for you. -If your 64-bit system doesn't have a `/lib` folder but only `/lib64` you may need to add this to your `/etc/fstab`: +**NOTE:** If your 64-bit system doesn't have a `/lib` folder but only `/lib64` you may need to change the `/lib` line in your `/etc/fstab` as follows: - /lib64 /bkp/lib64 none bind 0 0 + /lib64 /bkp/lib64 none bind 0 0 -and rename `/bkp/lib` to `/bkp/lib64`. Usually `/lib` is symlinked to `/lib64` though. +Don't forget to rename `/bkp/lib` to `/bkp/lib64`.:w -Finally add this to the end of your `/etc/ssh/sshd_config`: +When you're done, add this to the end of your `/etc/ssh/sshd_config`: Match Group backup ChrootDirectory /bkp/ diff --git a/install.sh b/install.sh index 43c5694..4ae64ca 100755 --- a/install.sh +++ b/install.sh @@ -140,6 +140,19 @@ if [[ $MODE == "install" ]]; then $MKDIR "$BKP_DIR"/usr/share/perl5 fi + # Append fstab entries + if ! grep -q "^# BEGIN: rs-backup-suite" /etc/fstab; then + if [[ "$DISTRIBUTION" == "Ubuntu" ]]; then + fstab_name="fstab_ubuntu" + elif [[ "$DISTRIBUTION" == "Synology" ]]; then + fstab_name="fstab_synology" + else + fstab_name="fstab" + fi + fstab_contents="$(cat ./server/etc/$fstab_name | sed "s#::BACKUP_ROOT::#$BKP_DIR#")" + echo "$fstab_contents" >> /etc/fstab + fi + # Do not overwrite existing config if [ ! -e "$BKP_DIR"/etc/rsnapshot.global.conf ]; then $CP ./server/bkp/etc/* "$BKP_DIR"/etc/ @@ -223,6 +236,9 @@ elif [[ "$MODE" == "uninstall" ]]; then sed -i '/^@[a-z]\+ \+\/usr\/sbin\/rs-rotate-cron [a-z]\+$/d' /etc/crontab fi + # Remove fstab entries + sed -i '/^# BEGIN: rs-backup-suite$/,/^# END: rs-backup-suite$/d' /etc/fstab + echo "Done." # Client component diff --git a/server/etc/fstab b/server/etc/fstab new file mode 100644 index 0000000..0bf31a2 --- /dev/null +++ b/server/etc/fstab @@ -0,0 +1,7 @@ +# BEGIN: rs-backup-suite +#/lib ::BACKUP_ROOT::/lib none bind 0 0 +#/dev ::BACKUP_ROOT::/dev none bind 0 0 +#/usr/bin ::BACKUP_ROOT::/usr/bin none bind 0 0 +#/usr/lib ::BACKUP_ROOT::/usr/lib none bind 0 0 +#/usr/share/perl5 ::BACKUP_ROOT::/usr/share/perl5 none bind 0 0 +# END: rs-backup-suite diff --git a/server/etc/fstab_synology b/server/etc/fstab_synology new file mode 100644 index 0000000..840d394 --- /dev/null +++ b/server/etc/fstab_synology @@ -0,0 +1,8 @@ +# BEGIN: rs-backup-suite +#/lib ::BACKUP_ROOT::/lib none bind 0 0 +#/dev ::BACKUP_ROOT::/dev none bind 0 0 +#/usr/bin ::BACKUP_ROOT::/usr/bin none bind 0 0 +#/opt/bin ::BACKUP_ROOT::/opt/bin none bind 0 0 +#/opt/lib ::BACKUP_ROOT::/opt/lib none bind 0 0 +#/opt/libexec ::BACKUP_ROOT::/opt/libexec none bind 0 0 +# END: rs-backup-suite diff --git a/server/etc/fstab_ubuntu b/server/etc/fstab_ubuntu new file mode 100644 index 0000000..09d47ce --- /dev/null +++ b/server/etc/fstab_ubuntu @@ -0,0 +1,7 @@ +# BEGIN: rs-backup-suite +#/lib ::BACKUP_ROOT::/lib none bind 0 0 +#/dev ::BACKUP_ROOT::/dev none bind 0 0 +#/usr/bin ::BACKUP_ROOT::/usr/bin none bind 0 0 +#/usr/lib ::BACKUP_ROOT::/usr/lib none bind 0 0 +#/usr/share/perl ::BACKUP_ROOT::/usr/share/perl none bind 0 0 +# END: rs-backup-suite