Article 5MGBQ I managed to make DejaDup more useful to myself. Sharing script.

I managed to make DejaDup more useful to myself. Sharing script.

by
jmgibson1981
from LinuxQuestions.org on (#5MGBQ)
I have been plagued by a proper backup solution. Over time I've tried DejaDup as it comes, rsync scripts with links, and a fair number of other apps.

DejaDup always won out due to it's pure simplicity but it lacked a simple feature. I wanted something that could backup more often than once a day, and that I could schedule with cron. The Deja gui just doesn't offer that.

I had a thought while reading a bit today. Deja Dup is a front end for Duplicity. I considered whether or not it can read a backup created by command line Duplicity. Turns out it can. And if you do your backups with Duplicity then you can control when and how often and can restore with the ease of the Deja Dup gui.

I set to work creating a script that could be run as root with root ssh key to your backup server. This can be changed to a non privileged user of course assuming user exists and and permissions are right. Must be run as root on the machines you are backing up due to it looping automatically through each user's /home/"$USER" directory.

https://gitlab.com/jmgibson1981/scri.../newbackups.sh

Code:#!/bin/sh
# tadaen sylvermane | jason gibson
# duplicity script to backup all users on given machine via hostname
# script meant to be run from a single location over nfs share. it has a
# local and server part differentiated by hostname variable. requires
# root ssh via key.

# tested in virtualbox with a source and target vm.

# variables #

SERVER=192.168.1.83
SERVERHN=testserver
SERVERBUPATH=/snapraid/pool/backups/homebackups
SSHFSMOUNT=/tmp/"$SERVERHN"backuptemp

# begin script #

if [ "$SERVERHN" != $(uname -n) ] ; then
case "$1" in
backups)
if [ "$USER" = root ] ; then
# users to be backed up #
for user in /home/* ; do
BUSER=$(basename "$user")
BACKUPLAUNCHER=/home/"$BUSER"/.local/share/applications/org.gnome.DejaDup.desktop
# adjust backups launcher to run script instead of program directly
# does by copying the .desktop file to the given users
# ~/.local/share/applications and adjusting to run this script instead
# of the program directly. script edits target information into
# deja dup via gsettings.
if [ ! -f "$BACKUPLAUNCHER" ] ; then
mkdir -p $(dirname "$BACKUPLAUNCHER")
cp /usr/share/applications/org.gnome.DejaDup.desktop \
"$BACKUPLAUNCHER"
chown -R "$BUSER":"$BUSER" /home/"$BUSER"
sed -i "s|Exec=deja-dup|Exec=${0} restore|" "$BACKUPLAUNCHER"
fi
# prep for each user and hostname. this will create backup
# folders as needed.
[ -d "$SSHFSMOUNT" ] || mkdir -p "$SSHFSMOUNT"
if ping -c 1 "$SERVER" ; then
# runs on backup server making sure the target directory exists.
ssh root@"$SERVER" "newbackups.sh create"
sshfs root@"$SERVER":/"$SERVERBUPATH" "$SSHFSMOUNT"
# sanity check for mountpoint
if ! mountpoint -q "$SSHFSMOUNT" ; then
echo "failed mount! exiting!"
exit 1
fi
fi
# temp directory creation for sshfs mounting
[ -d "$SSHFSMOUNT"/$(uname -n)/"$BUSER" ] \
|| mkdir -p "$SSHFSMOUNT"/$(uname -n)/"$BUSER"
# basics. this is what i use around here. would be a bit more involved
# if encryption required.
duplicity \
--exclude-if-present .nobackup \
--no-encryption \
--full-if-older-than 1M \
/home/"$BUSER" file://"$SSHFSMOUNT"/$(uname -n)/"$BUSER"
wait
# basics for me again. clean up over time.
duplicity remove-all-but-n-full 4 --force \
file://"$SSHFSMOUNT"/$(uname -n)/"$BUSER"
wait
# unmount sshfs
umount "$SSHFSMOUNT"
# run this function on the backup server setting the rwx as needed
# so users can read but can't delete or modify their existing backups
ssh root@"$SERVER" "newbackups.sh permissions"
done
fi
;;
restore)
# enters settings into deja dup gui for restoration. the users will need
# ssh access to the backup server. keys preferrable but can be done with
# name + password. This runs when the Backups / Deja Dup tool is called.
# if anythign changes you just change it here in the variables. as the
# script should be located on a central point (nfs share in my case) if I
# update it then it's automatically updated everywhere it's shared to.
gsettings set org.gnome.DejaDup.Remote uri \
"ssh://${SERVER}"
gsettings set org.gnome.DejaDup.Remote folder \
"${SERVERBUPATH}/$(uname -n)/${USER}"
deja-dup
;;
esac
else
case "$1" in
create)
# will create backup path in variable if not exist
[ -d "$SERVERBUPATH" ] || mkdir -p "$SERVERBUPATH"
;;
permissions)
# this will be run on the backup server. makes sure people can restore
# their backups while they are owned by root. also they cannot delete
# the backups themselves.
find "$SERVERBUPATH"/ \
-mindepth 2 \
-type d \
-exec chmod 755 {} \;
find "$SERVERBUPATH"/ \
-mindepth 2 \
-type f \
-exec chmod 644 {} \;
;;
esac
fi

# end script #latest?d=yIl2AUoC8zA latest?i=3TLrVONlFYQ:yoJjdWlTTCA:F7zBnMy latest?i=3TLrVONlFYQ:yoJjdWlTTCA:V_sGLiP latest?d=qj6IDK7rITs latest?i=3TLrVONlFYQ:yoJjdWlTTCA:gIN9vFw3TLrVONlFYQ
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments