How to migrate Navidrome

I have a Navidrome server before. Now because of I am living in Sweden, the latency is too high for connecting to the old server. So I create a new instance in Stockholm in Oracle, a free server, in order to get a better music experience. Now let me tell you how to migrate Navidrome to a new server.

How to migrate Navidrome

For my circumstance, I will use the same path in new server. If you want to use new path for music, you need to modify the database of Navidrome, which is not within the scope of this article. All in one sentence, you just need to copy /var/lib/navidrome/, /var/www/music/ to your new server and install Navidrome again, then you got the same Navidrome as the old one, all the playlist and password are same.

Log into your old server as root.

1
2
tar -cvzf navidrome_backup.tar.gz /var/lib/navidrome/
tar -cvzf music_backup.tar.gz /var/www/music/

Then transfer these two files to your new server using any way you can. For me, I used web server.

1
2
mv navidrome_backup.tar.gz /var/www/html/
mv music_backup.tar.gz /var/www/html/

Then log into your new server as root. For me, it is a brand new server so I need to install Nginx from the beginning.

1
2
3
4
5
apt update
apt upgrade
apt install nginx python3-certbot-nginx certbot vim ffmpeg
adduser navidrome
vim /etc/sudoers
1
navidrome	ALL=(ALL:ALL) ALL # add this in the last for temporary root permission, you can delete it atfer installation
1
2
3
4
5
6
7
su - navidrome
sudo install -d -o navidrome -g navidrome /opt/navidrome
sudo install -d -o navidrome -g navidrome /var/lib/navidrome
wget https://github.com/navidrome/navidrome/releases/download/v0.52.5/navidrome_0.52.5_linux_amd64.tar.gz # get the latest version in github release pages
sudo tar -xvzf navidrome_0.52.5_linux_amd64.tar.gz -C /opt/navidrome/
sudo chown -R navidrome:navidrome /opt/navidrome
exit
1
2
3
4
5
6
7
wget https://old.server/navidrome_backup.tar.gz
wget https://old.server/music_backup.tar.gz
tar -xvzf navidrome_backup.tar.gz
tar -xvzf music_backup.tar.gz
chown -R navidrome:navidrome /var/lib/navidrome/
chown -R www-data:www-data /var/www/music/
vim /etc/systemd/system/navidrome.service
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
[Unit]
Description=Navidrome Music Server and Streamer compatible with Subsonic/Airsonic
After=remote-fs.target network.target
AssertPathExists=/var/lib/navidrome

[Install]
WantedBy=multi-user.target

[Service]
User=navidrome
Group=navidrome
Type=simple
ExecStart=/opt/navidrome/navidrome --configfile "/var/lib/navidrome/navidrome.toml"
WorkingDirectory=/var/lib/navidrome
TimeoutStopSec=20
KillMode=process
Restart=on-failure

# See https://www.freedesktop.org/software/systemd/man/systemd.exec.html
DevicePolicy=closed
NoNewPrivileges=yes
PrivateTmp=yes
PrivateUsers=yes
ProtectControlGroups=yes
ProtectKernelModules=yes
ProtectKernelTunables=yes
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
RestrictNamespaces=yes
RestrictRealtime=yes
SystemCallFilter=~@clock @debug @module @mount @obsolete @reboot @setuid @swap
ReadWritePaths=/var/lib/navidrome

# You can uncomment the following line if you're not using the jukebox This
# will prevent navidrome from accessing any real (physical) devices
#PrivateDevices=yes

# You can change the following line to `strict` instead of `full` if you don't
# want navidrome to be able to write anything on your filesystem outside of
# /var/lib/navidrome.
ProtectSystem=full

# You can uncomment the following line if you don't have any media in /home/*.
# This will prevent navidrome from ever reading/writing anything there.
#ProtectHome=true

# You can customize some Navidrome config options by setting environment variables here. Ex:
#Environment=ND_BASEURL="/navidrome"
1
2
3
4
5
6
7
sudo systemctl daemon-reload
sudo systemctl start navidrome.service
sudo systemctl status navidrome.service
sudo systemctl enable navidrome.service
vim /etc/nginx/.htpasswd # copy this value in your old server, the path is /etc/apache2/.htpasswd
ln -s /etc/nginx/sites-available/music.new.server /etc/nginx/sites-enabled/
vim /etc/nginx/sites-available/music.new.server
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
server {
listen 80;
server_name music.new.server;

# Redirect HTTP to HTTPS
location / {
return 301 https://$host$request_uri;
}
}

server {
listen 443 ssl;
server_name music.new.server;

# SSL Configuration, comment these line until you applied a license for your domain
ssl_certificate /etc/letsencrypt/live/music.new.server/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/music.new.server/privkey.pem;

error_log /var/log/nginx/music_error.log;
access_log /var/log/nginx/music_access.log combined;

# WebDAV Configuration
location /webdav {
alias /var/www/music;
dav_methods PUT DELETE MKCOL COPY MOVE;
create_full_put_path on;
auth_basic "WebDAV Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
autoindex on; # 启用目录索引
}

# WebSocket and general proxy support
location / {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:4533;
proxy_read_timeout 600s;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

# Disable TRACE method
if ($request_method = TRACE) {
return 405;
}
}

1
service nginx restart

All done, have fun with your new music server!