LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-22-2021, 07:57 PM   #1
jmgibson1981
Senior Member
 
Registered: Jun 2015
Location: Tucson, AZ USA
Distribution: Debian
Posts: 1,159

Rep: Reputation: 395Reputation: 395Reputation: 395Reputation: 395
I managed to make DejaDup more useful to myself. Sharing script.


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 #
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Vmnet adapters are shown as "device not managed". There are two adapters vmnet1 and vmnet8 which are all not managed. kats99 Linux - Networking 4 11-01-2019 01:42 AM
backup dejadup cannot function due missing software; unable to locate missing package(s) mike3644 Linux - Software 1 05-03-2016 07:59 PM
LXer: How to backup your Ubuntu Desktop with DejaDup LXer Syndicated Linux News 0 03-04-2015 12:20 PM
[SOLVED] dejadup restore Pedroski Linux - Software 1 03-22-2012 05:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration