Skip to content

Commit

Permalink
Merge pull request #60 from 007revad/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
007revad authored Jun 13, 2024
2 parents e7fc199 + db6bc32 commit 52b636c
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 46 deletions.
7 changes: 7 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
v3.0.50
- Bug fix for Hyper backup where moving `@img_bkp_cache` could cause an error. Issue #54
- Bug fix Container Manager and Docker where moving `@docker` could cause an error. Issues #34 #38 #46
- Changed to not exit on error moving app's `@folders`.
- Changed from hardcoded 50GB buffer to user configurable buffer (used when checking if there's enough space to move folder).
- Bug fix for message showing `@download` if not enough space on target volume to move `@docker`.

v3.0.49
- Bug fix for Synology Drive still using `@synologydrive` on the original volume. Issue #55
- Now deletes `@eaDir` folders to try to prevent `mv: cannot remove '/volume#/@<folder>': Operation not permitted`. Issue #54
Expand Down
7 changes: 6 additions & 1 deletion syno_app_mover.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# buffer is used when checking if target volume has enough space
# Add 50 GB buffer so we don't fill the target volume

buffer=50

# backuppath should be in the format of /volume/sharename/folder
# For example:
# backuppath="/volume1/backups"
Expand All @@ -10,4 +15,4 @@ backuppath="/volume1/backups"
# Set to "0" to always backup
# skip_minutes is in minutes

skip_minutes="360"
skip_minutes=360
115 changes: 70 additions & 45 deletions syno_app_mover.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@
# DSM 6 to 7.1.1 bug fix for not detecting when package was not installed (for Restore mode).
#
#
# DONE Bug fix for moving `@img_bkp_cache`. Issue #54
# DONE Bug fix for moving `@docker`. Issues #34 #38 #46
#
# DONE Bug fix for not editing /var/packages/Calendar/etc/share_link.json. Issue #39
# DONE Bug fix for not moving @synocalendar if it exists. Issue #39
#
# DONE Added skip restore if last restore was less than n minutes ago.
# - Set skip_minutes in syno_app_mover.conf
# - Set skip_minutes in syno_app_mover.conf
# DONE Skip exit on error and skip processing app if backup all or restore all selected.
# DONE Changed to suggest changing volume location in app's settings for each app with volume settings when All selected.
# - Previously only showed how to edit volume location in app's settings for the last app processed.
Expand All @@ -50,7 +53,7 @@
# DONE Added check that the extra @ folders exist to prevent errors.
#
# DONE Added skip backup if last backup was less than n minutes ago.
# - Set skip_minutes in syno_app_mover.conf
# - Set skip_minutes in syno_app_mover.conf
#
# DONE Skip processing app if it failed to stop.
#
Expand Down Expand Up @@ -133,7 +136,7 @@
# DONE Bug fix when script updates itself and user ran the script from ./scriptname.sh


scriptver="v3.0.49"
scriptver="v3.0.50"
script=Synology_app_mover
repo="007revad/Synology_app_mover"
scriptname=syno_app_mover
Expand Down Expand Up @@ -379,6 +382,14 @@ if ! printf "%s\n%s\n" "$tag" "$scriptver" |
fi

conffile="${scriptpath}/${scriptname}.conf"
# Fix line endings
# grep can't detect Windows or Mac line endings
# but can detect if there's no Linux endings.
if grep -rIl -m 1 $'\r' "$conffile" >/dev/null; then
# Does not contain Linux line endings
sed -i 's/\r\n/\n/g' "$conffile" # Fix Windows line endings
sed -i 's/\r/\n/g' "$conffile" # Fix Mac line endings
fi


#------------------------------------------------------------------------------
Expand Down Expand Up @@ -705,7 +716,7 @@ move_pkg_do(){
#progbar "$pid" "$string"
#wait "$pid"
#progstatus "$?" "$string"
move_dir "$appdir"
exitonerror="no" && move_dir "$appdir"
# fi
fi
}
Expand Down Expand Up @@ -840,8 +851,14 @@ folder_size(){
if [[ -d "$1" ]]; then
# Get size of $1 folder
need=$(du -s "$1" | awk '{ print $1 }')
# Add 50GB so we don't fill volume
needed=$((need +50000000))
# Add buffer GBs so we don't fill volume
buffer=$(/usr/syno/bin/synogetkeyvalue "$conffile" buffer)
if [[ $buffer -gt "0" ]]; then
buffer=$((buffer *1000000))
else
buffer=0
fi
needed=$((need +"$buffer"))
fi
}

Expand All @@ -868,9 +885,14 @@ check_space(){

# Check we have enough space
if [[ ! $free -gt $needed ]]; then
echo -e "${Yellow}WARNING${Off} Not enough space to ${mode,,} "\
echo -e "${Yellow}WARNING${Off} Not enough space to ${mode,,}"\
"/${sourcevol}/${Cyan}$(basename -- "$1")${Off} to $targetvol"
echo -e "Free: $((free /1048576)) GB Needed: $((need /1048576)) GB\n"
echo -en "Free: $((free /1048576)) GB Needed: $((need /1048576)) GB"
if [[ $buffer -gt "0" ]]; then
echo -e " (plus $((buffer /1000000)) GB buffer)\n"
else
echo -e "\n"
fi
return 1
else
return 0
Expand Down Expand Up @@ -1010,7 +1032,14 @@ move_dir(){
if [[ -d "/${sourcevol:?}/${1:?}" ]]; then
if [[ ${mode,,} == "move" ]]; then
if [[ ! -d "/${targetvol:?}/${1:?}" ]]; then
mv -f "/${sourcevol:?}/${1:?}" "${targetvol:?}/${1:?}" &
if [[ $1 == "@docker" ]] || [[ $1 == "@img_bkp_cache" ]]; then
# Create @docker folder on target volume
create_dir "/${sourcevol:?}/${1:?}" "${targetvol:?}/${1:?}"
# Move contents of @docker to @docker on target volume
mv -f "/${sourcevol:?}/${1:?}"/* "${targetvol:?}/${1:?}" &
else
mv -f "/${sourcevol:?}/${1:?}" "${targetvol:?}/${1:?}" &
fi
pid=$!
string="${action} /${sourcevol}/$1 to ${Cyan}$targetvol${Off}"
progbar "$pid" "$string"
Expand Down Expand Up @@ -1056,7 +1085,7 @@ move_extras(){
# Change /volume1 to /volume2 etc
case "$1" in
ActiveBackup)
move_dir "@ActiveBackup" extras
exitonerror="no" && move_dir "@ActiveBackup" extras
# /var/packages/ActiveBackup/target/log/
if [[ ${mode,,} != "backup" ]]; then
if ! readlink /var/packages/ActiveBackup/target/log | grep "${2:?}" >/dev/null; then
Expand All @@ -1071,11 +1100,11 @@ move_extras(){
#echo ""
;;
ActiveBackup-GSuite)
move_dir "@ActiveBackup-GSuite" extras
exitonerror="no" && move_dir "@ActiveBackup-GSuite" extras
#echo ""
;;
ActiveBackup-Office365)
move_dir "@ActiveBackup-Office365" extras
exitonerror="no" && move_dir "@ActiveBackup-Office365" extras
#echo ""
;;
Chat)
Expand All @@ -1094,9 +1123,9 @@ move_extras(){
fi
;;
Calendar)
move_dir "@calendar" extras
exitonerror="no" && move_dir "@calendar" extras
if [[ -d "/@synocalendar" ]]; then
move_dir "$sourcevol/@synocalendar" extras
exitonerror="no" && move_dir "$sourcevol/@synocalendar" extras
fi
file="/var/packages/Calendar/etc/share_link.json"
if [[ -f "$file" ]]; then
Expand All @@ -1110,8 +1139,8 @@ move_extras(){
#echo ""
;;
ContainerManager|Docker)
echo -e "${Red}WARNING $action @docker could take a long time${Off}"
move_dir "@docker" extras
# Edit symlink before moving @docker
# If edit after it does not get edited if move @docker errors
if [[ ${mode,,} != "backup" ]]; then
if [[ $majorversion -gt "6" ]]; then
# /var/packages/ContainerManager/var/docker/ --> /volume1/@docker
Expand All @@ -1128,15 +1157,17 @@ move_extras(){
ln -s "${2:?}/@docker" "/var/packages/${pkg:?}/target/docker"
fi
fi
echo -e "${Red}WARNING $action @docker could take a long time${Off}"
exitonerror="no" && move_dir "@docker" extras
#echo ""
;;
DownloadStation)
echo -e "${Red}WARNING $action @download could take a long time${Off}"
move_dir "@download" extras
exitonerror="no" && move_dir "@download" extras
#echo ""
;;
GlacierBackup)
move_dir "@GlacierBackup" extras
exitonerror="no" && move_dir "@GlacierBackup" extras
if [[ ${mode,,} != "backup" ]]; then
file=/var/packages/GlacierBackup/etc/common.conf
if [[ -f "$file" ]]; then
Expand Down Expand Up @@ -1193,13 +1224,13 @@ move_extras(){
# backup_dir "@img_bkp_cache" "$sourcevol"
# backup_dir "@img_bkp_mount" "$sourcevol"

# move_dir "@img_bkp_cache"
# move_dir "@img_bkp_mount"
# exitonerror="no" && move_dir "@img_bkp_cache"
# exitonerror="no" && move_dir "@img_bkp_mount"
# echo ""
#fi
if [[ -d "/${sourcevol}/@img_bkp_cache" ]]; then
#backup_dir "@img_bkp_cache" "$sourcevol"
move_dir "@img_bkp_cache"
exitonerror="no" && move_dir "@img_bkp_cache" extras
echo ""
fi
;;
Expand All @@ -1225,14 +1256,14 @@ move_extras(){
fi
fi
fi
move_dir "@maillog" extras
move_dir "@MailPlus-Server" extras
exitonerror="no" && move_dir "@maillog" extras
exitonerror="no" && move_dir "@MailPlus-Server" extras
#echo ""
;;
MailServer)
move_dir "@maillog" extras
move_dir "@MailScanner" extras
move_dir "@clamav" extras
exitonerror="no" && move_dir "@maillog" extras
exitonerror="no" && move_dir "@MailScanner" extras
exitonerror="no" && move_dir "@clamav" extras
#echo ""
;;
Node.js_v*)
Expand All @@ -1250,7 +1281,7 @@ move_extras(){
fi
;;
PrestoServer)
move_dir "@presto" extras
exitonerror="no" && move_dir "@presto" extras
if [[ ${mode,,} != "backup" ]]; then
file=/var/packages/PrestoServer/etc/db-path.conf
if [[ -f "$file" ]]; then
Expand All @@ -1260,8 +1291,8 @@ move_extras(){
#echo ""
;;
SurveillanceStation)
move_dir "@ssbackup" extras
move_dir "@surveillance" extras
exitonerror="no" && move_dir "@ssbackup" extras
exitonerror="no" && move_dir "@surveillance" extras
if [[ ${mode,,} != "backup" ]]; then
file=/var/packages/SurveillanceStation/etc/settings.conf
if [[ -f "$file" ]]; then
Expand All @@ -1275,11 +1306,11 @@ move_extras(){
#echo ""
;;
synocli*)
#move_dir "@$1"
#exitonerror="no" && move_dir "@$1"
#echo ""
;;
SynologyApplicationService)
move_dir "@SynologyApplicationService" extras
exitonerror="no" && move_dir "@SynologyApplicationService" extras
if [[ ${mode,,} != "backup" ]]; then
file=/var/packages/SynologyApplicationService/etc/settings.conf
if [[ -f "$file" ]]; then
Expand All @@ -1289,8 +1320,8 @@ move_extras(){
#echo ""
;;
SynologyDrive)
move_dir "@synologydrive" extras
move_dir "@SynologyDriveShareSync" extras
exitonerror="no" && move_dir "@synologydrive" extras
exitonerror="no" && move_dir "@SynologyDriveShareSync" extras
if [[ ${mode,,} != "backup" ]]; then
file=/var/packages/SynologyDrive/etc/sharesync/daemon.conf
if [[ -f "$file" ]]; then
Expand Down Expand Up @@ -1319,12 +1350,12 @@ move_extras(){
#echo ""
;;
WebDAVServer)
move_dir "@webdav" extras
exitonerror="no" && move_dir "@webdav" extras
#echo ""
;;
Virtualization)
move_dir "@GuestImage" extras
move_dir "@Repository" extras
exitonerror="no" && move_dir "@GuestImage" extras
exitonerror="no" && move_dir "@Repository" extras
# VMM creates /volume#/vdsm_repo.conf so no need to move it
#echo ""
;;
Expand Down Expand Up @@ -1482,14 +1513,6 @@ if [[ ${mode,,} != "move" ]]; then
echo -e "Line ${LINENO}: ${Error}ERROR${Off} $conffile not readable!"
exit 1 # Conf file not readable
fi
# Fix line endings
# grep can't detect Windows or Mac line endings
# but can detect if there's no Linux endings.
if grep -rIl -m 1 $'\r' "$conffile" >/dev/null; then
# Does not contain Linux line endings
sed -i 's/\r\n/\n/g' "$conffile" # Fix Windows line endings
sed -i 's/\r/\n/g' "$conffile" # Fix Mac line endings
fi

# Get and validate backup path
backuppath="$(/usr/syno/bin/synogetkeyvalue "$conffile" backuppath)"
Expand Down Expand Up @@ -1864,6 +1887,8 @@ backup_extras(){
elif [[ ${mode,,} == "restore" ]]; then
extrabakvol="$targetvol"
fi
echo -e "NOTE: A backup of ${Cyan}$1${Off} is required"\
"for recovery if the move fails."
echo -e "Do you want to ${Yellow}backup${Off} the"\
"${Cyan}$1${Off} folder on $extrabakvol? [y/n]"
read -r answer
Expand Down Expand Up @@ -1951,7 +1976,7 @@ process_packages(){
# Check we have enough space
if ! check_space "/${sourcevol}/@docker" "${targetvol}"; then
ding
echo -e "${Error}ERROR${Off} Not enough space on $targetvol to ${mode,,} ${Cyan}@download${Off}!"
echo -e "${Error}ERROR${Off} Not enough space on $targetvol to ${mode,,} ${Cyan}@docker${Off}!"
process_error="yes"
if [[ $all != "yes" ]]; then
exit 1 # Skip exit if mode is All
Expand Down

0 comments on commit 52b636c

Please sign in to comment.