Move a Synology Package from a volume to another

I wanted to replace the smallest disks of my NAS with bigger ones. Unfortunately, some packages where installed on those. To avoid uninstalling/reinstalling everything, I did wrote a shell script which does the job, as well as a Package for Synology to offer a web interface.

Click to Read More

Here the first version of my script:

[shell] #!/bin/bash

TARGET=$1
PACKAGE=$2

if [[ $PACKAGE == "" ]] then
echo "Usage: mvpkg Target Package"
echo " Target must be like ‘volumex’ where x is a numeric."
echo " Package must be the name of a package."
exit
fi

if [[ $TARGET != volume[0-9]* ]] then
echo "Usage: mvpkg Target Package"
echo " Target must be like ‘volumex’ where x is a numeric."
echo " Package [$PACKAGE] must be the name of a package."
exit
fi

#Check the package and check the result: "enable" (is start), "disable" (is stop) or "does not exist"
output=$(/usr/syno/sbin/synoservicecfg –status "pkgctl-$PACKAGE" | grep Service)

if [[ $output == *"does not exist"* ]] then
echo "The service $PACKAGE can’t be found."
exit
else
#find the current volume of the package and its link
output=$( ls -la /var/packages/*/target | grep "/$PACKAGE/")

link=$(echo $output | grep -oP "\/var/packages/.*/target")
volume=$(echo $output | grep -oP "volume\d*")
path=$(echo $output | grep -oP "\/volume.*")

if [[ $link != "/var/packages/$PACKAGE/target"* ]] then
echo "The service $PACKAGE is not correctly installed."
exit
fi

if [[ $volume != "volume"* ]] then
echo "The service $PACKAGE can’t be located."
exit
fi

if [[ $volume == $TARGET ]] then
echo "The service $PACKAGE is already on $TARGET."
exit
fi

if [[ "$path" != "/$volume/@appstore/$PACKAGE" ]] then
echo "The service $PACKAGE does not have a standard location."
exit
fi

#List Packages with dependency on this one
#/usr/syno/sbin/synoservicecfg –reverse-dependency pkgctl-$PACKAGE

#Stop the package and all its dependencies
output=$(/usr/syno/sbin/synoservicecfg –hard-stop "pkgctl-$PACKAGE" | grep warn)

if [[ $output != *"have been set"* ]] then
echo "The service $PACKAGE couldn’t be stopped."
exit
fi

if [ -d "/$TARGET/@appstore/$PACKAGE" ]; then
mv "/$TARGET/@appstore/$PACKAGE" "/$TARGET/@appstore/$PACKAGE-$(date -d "today" +"%Y%m%d%H%M").log"
fi

#remove the link on the previous volume
rm -f "$link"

#move the package
mv "$path" /$TARGET/@appstore

#link with the package on the new volume
ln -s "/$TARGET/@appstore/$PACKAGE" "$link"

#Replace link also in local
local="/usr/local/$PACKAGE"
if [ -L "$local" ]; then
rm -f "$local"
ln -s "/$TARGET/@appstore/$PACKAGE" "$local"
fi

#update settings
sed -i "s/$volume/$TARGET/" "/usr/syno/etc/packages/$PACKAGE/*" &>/dev/null

if [[ $output != *"is enabled"* ]] then
echo "The service $PACKAGE didn’t restart properly once moved from $volume to $TARGET."
else
echo "The service $PACKAGE has been moved successfuly from $volume to $TARGET."

#Restart packages depending on the one moved
output=$(/usr/syno/sbin/synoservicecfg –reverse-dependency "pkgctl-$PACKAGE")

output="$(echo $output | grep -Po "pkgctl-([^\]]*)")"
for string in $output
do
/usr/syno/sbin/synoservicecfg –start "$string"
done
fi

#Restart the package and all its dependencies
output=$(/usr/syno/sbin/synoservicecfg –hard-start "pkgctl-$PACKAGE" | grep Service)

#Check if the package has been correctly restarted
output=$(/usr/syno/sbin/synoservicecfg –is-enabled "pkgctl-$PACKAGE")
fi
[/shell]

It is inspired from this post.

I did use it to move: AudioStation, CloudStation, DNSServer, NoteStation, PHP5.6, PHP7.0.

During the move, the package could temporary appear in the Package Center as needing to be repaired:

Repair Package
Repair Package444

Simply wait until the operation is completed and click next on “Refresh” in Package Center. Also, check that no other service was stopped but not restarted !! Restarting other services with dependency is not (yet) managed by the script.

WARNING: Moving some packages resulted in troubles (Packages never able to restart). Ex.: Apache Http Server 2.2 and 2.4, the Node.js, Unofficial Java Installer, WordPress. These packages did not restart properly after being moved. I still have to investigate why, but they displayed the error “failed to run the package service” for ever (even after restarting the NAS). Something I known is that there are also Symlinks onto packages in /usr/local/. My script takes those into account. But there are possibly other such dependencies somewhere else ?! Most package could fortunately be returned in their orignal state very easily by moving them back to their original volume.

Important notice

MariaDB. Before moving it, open it via the DSM main menu and change the volume where the DB files are stored.

If you wonder which package is on which volume, the easiest is to run this command in a shell: ls -la /var/packages/*/target

Troubleshooting

WordPress. After moving, it was stuck in the “repair state”. I simply backuped its folder (/volumex/web/wordpress => /volumex/web/wordpress.bkp), clicked on Repair, reconfigured it to use a new DB, stopped it once fully reinstalled, deleted its new folder and replaced it with the backup (/volumex/web/wordpress.bkp => /volumex/web/wordpress) before restarting wordpress and deleting the new DB.

Node.jsFileBot-Node and the Unofficial Java Installer. I simply clicked on Repair to fix them.

Plex Media Server. during y first attempts, it didn’t restart. I did simply install manually the latest version and the “update” fixed the problem without loosing any setting/library/etc… With the latest version of my script, the move succeeded.

Can’t restart. Look into Package’s installation path, for config files possibly still pointing at the old volume. Use for this purpose a command like:  find -L /var/packages/<package_name>/ -type f -print0 | xargs -I {} -0 grep -l “volumex” “{}”

If you find such config files, possibly update them by replacing the old volume (volumex) with the new volume (volumez) using a command like: sed -i “s/volumex/volumez/” <config_file_path>

Stuck ? If you can’t stop/restart a service correctly and can update this one manually, then delete it via a console, Click next Refresh in the Package Center and reinstall it:

  • ls -la /var/packages/<package_name>/target   => this is showing you the volume<x> where it’s installed
  • rm -R /var/packages/<package_name>
  • rm -R /usr/syno/etc/packages/<package_name>
  • rm -R /volume<x>/@appstore/<package_name>
  • rm -f /usr/syno/synoman/webman/3rdparty/<package_name>
  • rm -f /usr/local/<package_name>

Script & Package

I did create a “Synology Package” to be able to move packages easily from the DSM. You can find it on my own Synology Repository (See Blog’s menu “SPK Server”). You will find the script in the Package if you “unzip” it, in \package\ui\mvpkg.sh

Package Mover
Package Mover
[EDIT 13-10-2017] I have added support in the package to start/stop/delete packages, display reverse and forward dependencies. Only delete a packages if you are screwed.

[EDIT 24-02-2018] The sources for my package are available on GitHub (named Package Manager).

[EDIT 23-12-2018] Since a recent update of DSM, the feature to list dependencies between packages does not work anymore.

Loading


Categories:

Tags:


Comments

41 responses to “Move a Synology Package from a volume to another”

  1. Edd Avatar
    Edd

    fantastic package keep up the great work

  2. Andrew McLean Avatar

    This is amazing! I write the article you said your script was inspired by.

    I can’t wait to install this package and try it out!

    1. Valery Letroye Avatar

      Hello Andrew,

      I take this opportunity to tell you “a big thx” for sharing in the first place on how to do this! It really helped a lot.
      If you pass by Bruxelles, I owe you some local beers 😉

      Cheers,

  3. Andrew McLean Avatar

    I tried installing the package on a test DS3617xs box. It didn’t install and gave me the following error: Please install the following package(s) before installing this package: Init_3rdparty.

    I did some digging and I found a package source for it (https://www.cphub.net). Init_3rdparty installed without a hitch and your package installed next without further errors.

    1. Valery Letroye Avatar

      Yes, so far, my package has this dependency. I tried to get rid if it, using this trick: http://www.robvanaarle.com/blog/2014/08/embedded-php-app-without-dependencies-for-synology-nas
      Unfortunately, it’s then missing adequate rights to move the packages (must run as root to be able to call the /usr/syno/sbin/synoservicecfg)

      1. David L Merchant Avatar
        David L Merchant

        Valery – Is there a chance you could add the Synology RS-2418+ to the repository so I could install this package on my NAS? Thanks!

        Dave

        1. Valery Letroye Avatar

          Hi David,

          Did you try to install the latest version published on my SPK Server ? It has not restriction on any architecture: http://olympe.letroye.be/sspks/?arch=all
          PS.: The list of architectures on my SPK server is not up-to-date, reason why you don’t see the RS-2148+ 😉

  4. Connie P. Avatar
    Connie P.

    Most of my packages succesfully moved from volume 1 (a 2% life expectation left SSD) to volume 3 (a brand new SSD/volume to replace my old volume 1). However plex needs a bit more explaining for me if that’s possible. I can stop the service, move it from volume 1 to volume 2 and then I see the package manager asking me to repair the broken plex package…

    I then tried manually installing the newest plex package, but whenever I do so it wants to install to volume 1 again. How exactly do I change that to volume 3? Hope to hear from you!

    So far a big thanks for your script!

    1. Valery Letroye Avatar

      With a previous version of my script, moving Plex just resulted in Plex not starting anymore.
      I fixed this problem (Plex not starting) bu manually installing the latest version *on the same volume*.
      Next, I did improve my script and was finally able to move Plex successfully.

      But notice that I don’t have any plugin installed within Plex. Maybe there is a problem with moving the plugins ?

      Unfortunately, as I don’t have several volumes anymore, it’s difficult for me to reproduce anything :/

  5. Dan Avatar
    Dan

    hi
    i’d like to move deluge to volumeUSB1. is it possible? i’ve modded the script to allow usb1, but the package reads as needing repair 🙁
    thanks!

    1. Valery Letroye Avatar

      I really don’t have experience with installing packages on a usb drive (Never tried/never read it was possible) and with deluge. You should parse all files of Deluge to find if the volume is used in any one.

    2. Bjorn jacobs Avatar
      Bjorn jacobs

      how did u do this?

      1. Valery Letroye Avatar

        Dan has patched the file mvpkg.php which is in my SPK. I presume he modified the following line to list the USB devices in addition to the Volumes:

        $volumeNames = shell_exec(‘df -la –output=target | grep volume’);

        I will have a look and let you know (in your latest post in this thread).

  6. Floris Avatar
    Floris

    Hi, thanks for this great tool!

    I want to migrate my two disk NAS to btrfs, do you know if your tool works with moving the following packadges?

    Mailplus server
    Mailplus
    Drive
    Moments
    Docker

    Thanks!!

    1. Valery Letroye Avatar

      Unfortunately, I didn’t test my package with those apps… And as they are not “basic” apps, I would not take the risk without validating first on a test NAS.

  7. Max Avatar
    Max

    Hi, I’m in the same position as most other here, I want to move my Surveillance Station on DSM 6.2.1 from volume 2 to volume 1.
    Now I moved the shared folder with the recordings and such (“surveillance”) already to vol 1 using the system settings.
    I’m a little afraid to try out moving the Surveillance Station itself, as TONS of settings are stored there for each camera, and there is no way of backing them up beforehand.

    Has anyone tried it out with Surveillance Station on a new DSM like 6.2 yet? Thanks!

    1. Valery Letroye Avatar

      Are you sure that you cannot backup the settings of all your cam : https://www.synology.com/en-en/knowledgebase/Surveillance/help/SurveillanceStation/backup

      If doable, you would simply have to uninstall, reinstall on volume 1 and restore the settings.

      V.

  8. J Smokie Avatar
    J Smokie

    I’ve tried to install the Mods-PackageManger using the latest DSM software and it installs correctly. However when I try to run the package I get the following error “Sorry, the page you are looking for is not found.”

    1. J Smokie Avatar
      J Smokie

      I found the problem. I didn’t have PHP 7.0 installed. Once I installed 7.0 the app was able to run properly.

  9. PHC606 Avatar
    PHC606

    I’ve been battling doing this manually for too long, wish i found this tool sooner.
    I’ve used this app to move Surveillance Station on 6.2, (note i backed up all the cam configs, and was already using a different volume for storage) however this amazing app did the rest.

    I also move mailstation and mail server with no issues.

    am about to move a big Plex install…

    1. Valery Letroye Avatar

      Notice that after moving Plex, the package could have troubles to restart. In that case, simply manually “upgrade” with the latest version of Plex (even if you already have that version). this “reinstallation”, which occurs on the new volume, did fix the problem for me….

  10. casperse Avatar
    casperse

    I am also trying to move as many apps as possible to a new volume.
    I have installed all the dependencies and I get this when running the app

    I get this error message
    https://192.168.0.10/webman/3rdparty/MODS_PackageManager/mvpkg.php might be temporarily down or it may have moved permanently to a new web address.

    I have tried different paths and I am running the webservice, PHP and 3rd party app

    1. Valery Letroye Avatar

      Something does not work as expected. Your DSM should open the PackageManager via its Admin Port. I.e.: something like https://YourIP:YourDSMAdminPort/etc

      Try to add manually your DSM Admin Port in the URL (Ex.: 5001 is the default https port): https://192.168.0.10:5001/webman/3rdparty/MODS_PackageManager/mvpkg.php

    2. Aseem Avatar

      I had the same issue, moving to different browser worked for me :

      https://github.com/vletroye/SynoPackages/issues/4#issuecomment-504702857

  11. David L Merchant Avatar
    David L Merchant

    Valery – Is there a chance you could add the Synology RS-2418+ to the repository so I could install this package on my NAS? Thanks!

    Dave

    1. Valery Letroye Avatar

      Hi David, this Package is not limited to any architecture. So, you should be able to download it via http://olympe.letroye.be/sspks/?arch=all and install it.

  12. oriddlero Avatar
    oriddlero

    How does this package work (how do i use it)? I just installed it and i don’t see the options to use it anywhere.

    1. Valery Letroye Avatar

      You should have an icon “Package Manager” in the DSM Main Menu. If it’s not there, then try to refresh the web page in your browser (CTRL-F5)

  13. Rastislav Avatar
    Rastislav

    Hi Valery
    I have issue with MODS Package Manager.
    I was moving packages from HDD volume to SSD volume without any issues.
    Then I have moved the Package manager and then I got the issue to run the package.
    Stop-Start does not work
    Re-install to SSD volume or HDD volume does not work.
    it displays the MVPKG.php only.

  14. Rastislav Avatar
    Rastislav

    Hi Valery
    MODS Package Manager was running till moving the package itself. from that time only php file is shown.
    any hints?

    1. Valery Letroye Avatar

      Alas no, sorry. I never tried that myself 😀
      And I can’t test it anymore as I have now only one volume remaining :/

      I presume you tried to uninstall “MODS Package Manager” and reinstall it ?

  15. Ramz Avatar
    Ramz

    I was researching how to move apps and came across a few pages that used the command line but your app was a user experience dream. Thank you.

    Some notes:
    1. I had to install the webstation app as a dependency (I already had Php 7 installed)
    2. Download station needed pointing to volume2 for its temporary file location. Stumbled across that before pulling volume1 out so don’t know if it would have self-corrected if it didn’t see volume1 anymore.

    once again, thank you!

  16. Kim Thurnherr Avatar
    Kim Thurnherr

    Hi there

    Great work, i’d love to check this out too, but the spk server is not responding. Is this still up for download?

    Best
    Kim

    1. Valery Letroye Avatar

      Hi. The power supply of my NAS is dead. I did return it to Synology and they will send me a new one (as still under guaranty).
      This is why you can’t access to my SPK server anymore for the moment.

      You can however get an unsigned version of that SPK on GitHub too (See https://github.com/vletroye/SynoPackages/tree/master/MODS%20Package%20Manager)

  17. Bjorn jacobs Avatar
    Bjorn jacobs

    What would I need to change to alow copying to volumeUSB1? (sonarr and radarr)

    I did that manualy in the past, but this script seems to be a better idea.

    1. Valery Letroye Avatar

      There are a few changes to be done to support USB volumes…
      Mainly all Regular Expression matching “volume” should be replaced with “volume(USB)*”

      You can login into your NAS (e.g.: using putty) and go to the installation dir of the package to do the required changes:
      cd /var/packages/MODS_PackageManager/target/ui/

      Ex: in the file mvpkg.php (using vi) you have to add the pattern (USB)* in the line 321:
      if ( preg_match(‘/volume(USB)*\\d+/’, $volumeName, $out) ) {

      etc… But as I am stuck at home (lock down in Belgium due to the coronavirus), I will take some time today to do all the changes and publish a new packages 😉

      1. Valery Letroye Avatar

        I did upload a new version v0.0-0086 on my SPK Server (https://www.beatificabytes.be/sspks/?arch=all#).
        It is allowing a move to \volumeUSBx

        But notice that packages moved to volumeUSB will appear as “in error” in the Package Manager. No idea why (Help would be appreciated).
        Nevertheless, the packages used for my tests (TextEditor and synOCR) work fine on a volumeUSB.

        Sources have been pushed to https://github.com/vletroye/SynoPackages/tree/master/MODS%20Package%20Manager

  18. Bob M Avatar
    Bob M

    THANK YOU so much for adding this functionality as a Synology “package” – WOW – this saved me HOURS of work!

  19. Peter Avatar
    Peter

    DSM 7.x How use this Package Manager ?

    1. Valery Letroye Avatar

      Too many changes between DSM 6.x and 7.x, especially with Security (Packages won’t run as root/admin).
      So, my packages won’t work as-is and I don’t have enough free time to review them. Sorry.

      1. Roberto Avatar
        Roberto

        what a pity to know that!

Leave a Reply

Your email address will not be published. Required fields are marked *