Skip to content
Permalink
Browse files

Sync now targets individual dirs stored in array

  • Loading branch information...
jmcnatt committed Jul 2, 2017
1 parent 3d68391 commit 644ac2b65f2e2e2b3d231f4bb3039d87cbccfec2
Showing with 42 additions and 26 deletions.
  1. +42 −26 boxsync
68 boxsync
@@ -1,28 +1,44 @@
#!/bin/bash

logpath=/var/log/boxsync
boxdavlocation=/mnt/box-dav
boxdest=/mnt/box

writelog() {
while IFS= read -r line; do
printf "%s boxsync: %s\n" "$(date +'%F %H:%M:%S')" "$line" >> $logpath
done
}

# Mount Box location
/bin/mount -t davfs https://dav.box.com/dav $boxdavlocation
echo "Mount box-dav at $boxdavlocation" | writelog

# Begin rsync
# -u update
# -r recursive
# --progress show progress
# --delete delete files not in source
echo "Starting sync" | writelog
/bin/rsync -urh --progress --delete --exclude 'Podcasts' --exclude 'Playlists' $boxdavlocation/* $boxdest | writelog
/bin/rsync -rh --progress --delete --temp-dir=/tmp $boxdest/Playlists/ $boxdavlocation/Playlists | writelog

# Unmount Box location
echo "Unmount box-dav at $boxdavlocation" | writelog
/bin/umount $boxdavlocation
# Define globals
logpath=/var/log/boxsync
boxdavlocation=/mnt/box-dav
boxdest=/mnt/box
boxsyncdirs=('Audio Books' 'Classical' 'Country' 'Electronic' 'Metal' 'Pop' 'R&B' 'Rock' 'Soundtracks' 'Vocal' 'World')

# Define functions
writelog() {
while IFS= read -r line; do
printf "%s boxsync: %s\n" "$(date +'%F %H:%M:%S')" "$line" >> $logpath
done
}

# Set $IFS
IFSORIG=$IFS
IFS=$(echo -en "\n\b")

# Mount Box location
/bin/mount -t davfs https://dav.box.com/dav $boxdavlocation
echo "Mount box-dav at $boxdavlocation" | writelog

# Begin rsync for each directory in boxsyncdirs
# -u update
# -r recursive
# --progress show progress
# --delete delete files not in source
echo "Starting sync" | writelog

for i in ${boxsyncdirs[@]}; do
echo "Syncing directory $i" | writelog
/bin/rsync -urh --progress --delete $boxdavlocation/$i $boxdest/$i | writelog
done

# Sync playlists back to Box
/bin/rsync -rh --progress --delete --temp-dir=/tmp $boxdest/Playlists/ $boxdavlocation/Playlists | writelog

# Unmount Box location
echo "Unmount box-dav at $boxdavlocation" | writelog
/bin/umount $boxdavlocation

# Restore IFS
IFS=$IFSORIG

0 comments on commit 644ac2b

Please sign in to comment.
You can’t perform that action at this time.