OpenELEC Forum
rsync media backup script - Printable Version

+- OpenELEC Forum (https://forum.openelec.tv)
+-- Forum: Generic Forum (https://forum.openelec.tv/forumdisplay.php?fid=5)
+--- Forum: OPENELEC ADDONS (https://forum.openelec.tv/forumdisplay.php?fid=29)
+---- Forum: unofficial OpenELEC Addons (https://forum.openelec.tv/forumdisplay.php?fid=31)
+---- Thread: rsync media backup script (/showthread.php?tid=73330)



rsync media backup script - jer-az - 10-14-2014

Huge thanks to neo2001 for sharing his backup script. I tweaked it to backup each media folder on my OE machine and it's exactly what I wanted. Smile

Next I'll figure out how to
xbmc exportlibrary(video,true,thumbs,overwrite,actorthumbs)
sleep 420

Obviously, you need to install rsync from openelec unofficial repo and if anything goes horribly wrong, you only have yourself to blame.
on a side note,
chmod -x OEmediabackup.sh doesn't work so instead I used:
echo "#!/bin/sh" > /storage/OEmediabackup.sh && chmod +x /storage/OEmediabackup.sh nano OEmediabackup.sh
and used text editor (like nano or notepad ++) to paste the script.
Code:
#!/bin/sh
# Set your own variables
TARGET_MOUNTPOINT=/var/media/mybackup
TARGET_DIR=$TARGET_MOUNTPOINT/Media
SOURCE_DIR=/storage
RSYNC_OPTIONS="--recursive --ignore-existing --verbose --itemize-changes --human-readable"

# Append --dry-run to rsync call if test run only
if [ "$1" = "-t" -o "$1" = "--test" -o "$1" = "--dry-run" -o "$1" = "-n" ]; then
RSYNC_OPTIONS="$RSYNC_OPTIONS --dry-run"
echo "This is a DRY RUN only!"
fi
# Check first if source and target dirs exist
if [ -d "$SOURCE_DIR/videos" -a -d "$TARGET_DIR/videos" ]; then
echo "Backing up $SOURCE_DIR/videos/* $TARGET_DIR/videos"
rsync $RSYNC_OPTIONS $SOURCE_DIR/videos/* $TARGET_DIR/videos
else
echo "Error: Target or source dir not found!"
exit 1
fi
# Check first if source and target dirs exist
if [ -d "$SOURCE_DIR/movies" -a -d "$TARGET_DIR/movies" ]; then
echo "Backing up $SOURCE_DIR/movies/* $TARGET_DIR/movies"
rsync $RSYNC_OPTIONS $SOURCE_DIR/movies/* $TARGET_DIR/movies
else
echo "Error: Target or source dir not found!"
exit 1
fi
# Check first if source and target dirs exist
if [ -d "$SOURCE_DIR/tvshows" -a -d "$TARGET_DIR/tvshows" ]; then
echo "Backing up $SOURCE_DIR/tvshows/* $TARGET_DIR/tvshows"
rsync $RSYNC_OPTIONS $SOURCE_DIR/tvshows/* $TARGET_DIR/tvshows
else
echo "Error: Target or source dir not found!"
exit 1
fi
# Check first if source and target dirs exist
if [ -d "$SOURCE_DIR/music" -a -d "$TARGET_DIR/music" ]; then
echo "Backing up $SOURCE_DIR/music/* $TARGET_DIR/music"
rsync $RSYNC_OPTIONS $SOURCE_DIR/music/* $TARGET_DIR/music
else
echo "Error: Target or source dir not found!"
exit 1
fi
# Check first if source and target dirs exist
if [ -d "$SOURCE_DIR/pictures" -a -d "$TARGET_DIR/pictures" ]; then
echo "Backing up $SOURCE_DIR/pictures/* $TARGET_DIR/pictures"
rsync $RSYNC_OPTIONS $SOURCE_DIR/pictures/* $TARGET_DIR/pictures
else
echo "Error: Target or source dir not found!"
exit 1
fi



rsync media backup script - tower41000 - 10-14-2014

hi,

maybe because /media is a link , not a real directory.

it points to /var/media.

i m not a bash guru, just a base linux user, but could be worth checking fisrt thing.


rsync media backup script - lrusak - 10-14-2014

Did you install the rsync addon?


rsync media backup script - neo2001 - 10-17-2014

This is the script I'm using at the moment for my backups:

Code:
#!/bin/sh
# All backup media *have to* have the filesystem label "Backup"
TARGET_MOUNTPOINT=/var/media/Backup
TARGET_DIR=$TARGET_MOUNTPOINT/tv-shows
SOURCE_DIR=/var/media/Content/video/tv-shows
RSYNC_OPTIONS="--archive --delete --size-only --times --verbose --itemize-changes --human-readable"

# Append --dry-run to rsync call if test run only
if [ "$1" = "-t" -o "$1" = "--test" -o "$1" = "--dry-run" -o "$1" = "-n" ]; then
RSYNC_OPTIONS="$RSYNC_OPTIONS --dry-run"
echo "This is a DRY RUN only!"
fi

# Check first if source and target dirs exist
if [ -d "$SOURCE_DIR" -a -d "$TARGET_DIR" ]; then
echo "Running rsync ..."
echo "Source: $SOURCE_DIR"
echo "Target: $TARGET_DIR"
rsync $RSYNC_OPTIONS $SOURCE_DIR/ $TARGET_DIR/
else
echo "Error: Target or source dir not found!"
exit 1
fi

The previous one is a "simplified" version of the next one, I wrote/used before:
Code:
#!/bin/sh
TARGET_DEVICE=/dev/sdc1
TARGET_MOUNTPOINT=/var/media/Backup
SOURCE_DIR=/var/media/Content/video/tv-shows
TARGET_DIR=/var/media/Backup/tv-shows

MOUNT_OPTIONS="-t ext4 -o rw,nosuid,nodev,noexec,noatime"
RSYNC_OPTIONS="--archive --delete --size-only --times --verbose --itemize-changes --human-readable"

# Append --dry-run to rsync call if test run only
if [ "$1" = "-t" -o "$1" = "--test" -o "$1" = "--dry-run" -o "$1" = "-n" ]; then
RSYNC_OPTIONS="$RSYNC_OPTIONS --dry-run"
echo "This is a DRY RUN only!"
fi

# Clean up
cleanup(){
# Unmount device (if mounted)
while mountpoint -q $TARGET_MOUNTPOINT && ! umount $TARGET_MOUNTPOINT ; do
sleep 1
done

# Remove dir
if [ -d "$TARGET_MOUNTPOINT" ]; then
rmdir $TARGET_MOUNTPOINT
fi

echo "$TARGET_MOUNTPOINT unmounted."
}

mkdir -p $TARGET_MOUNTPOINT

# Check if already mounted
if ! mountpoint -q $TARGET_MOUNTPOINT ; then
echo "Mounting backup drive to $TARGET_MOUNTPOINT ..."
if ! mount $MOUNT_OPTIONS $TARGET_DEVICE $TARGET_MOUNTPOINT ; then
echo "Error mounting $TARGET_MOUNTPOINT"
cleanup
exit 1
fi
fi

# Check first if source and target dirs exist
if [ -d "$SOURCE_DIR" -a -d "$TARGET_DIR" ]; then
echo "Running rsync ..."
echo "Source: $SOURCE_DIR"
echo "Target: $TARGET_DIR"
rsync $RSYNC_OPTIONS $SOURCE_DIR/ $TARGET_DIR/
cleanup
else
echo "Error: Target or source dir not available!"
cleanup
exit 1
fi

I dropped the manual mounting part, because OpenELEC's auto-mounting does the job just fine for me (and my system) - that and I couldn't exclude the drive from auto-mounting using udev anymore, since starting from a certain version OpenELEC ignored my user udev-rules using the file system label to prevent mounting it.

Of course you always need the rsync Addon to be installed.

Also this is only for one directory - but you could make the dir a variable and call the script from another one with individual parameters - or just use multiple script files with the hard coded paths.


rsync media backup script - jer-az - 10-17-2014

yes that could be. but when I call each command from ssh it works perfectly
BTW Thank you for the reply


rsync media backup script - jer-az - 10-17-2014

Thank you so much for this!!! I'll give it a shot later today.


Iron Fire Advocates Making Sturdy Furniture Products - FrankJScott - 07-08-2020

Always a fan of this blog Smile Btw, I highly recommend this iron fire furniture specialist at this hop over to this website website not to mention this click for info forum or take a look at this view it profile along with this link page and don't forget this check out here profile and finally this linked here page is great too. Also worth mentioning is this page website, as well as find page and finally this find more site and always this dig this site, as well as you could try these out website not to mention this find out here website or take a look at this read this article forum along with this source forum and don't forget this see page website. Iron Fire Specialises In Developing Resilient Furniture Items b0ebe7e