# PMS Database backup to external location - Ubuntu

**URL:** <https://forums.plex.tv/t/pms-database-backup-to-external-location-ubuntu/787264>\
**Category:** Plex Media Server\
**Tags:** server-linux\
**Created:** [April 9, 2022, 1:41pm UTC](https://forums.plex.tv/t/pms-database-backup-to-external-location-ubuntu/787264 "2022-04-09T13:41:57Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![LLundberg](https://avatars.discourse-cdn.com/v4/letter/l/4af34b/32.png) [@LLundberg](https://forums.plex.tv/u/LLundberg)\
**Post date:** [April 9, 2022, 1:41pm UTC](https://forums.plex.tv/t/pms-database-backup-to-external-location-ubuntu/787264/1 "2022-04-09T13:41:57Z")

</div>

Server Version#: 1.24.4.5081  
Hi all,  
I have a HP Proliant N54 running PMS Ubuntu 20.04.2 LTS.  
I believe that Plex does backups internally every three days. What I want to do is to set up backup to a remote NAS. Seems pointless doing backups to the same disk, if the disk dies the backup is gone with it.  
Is there a script of some sort to do this? I don’t think I can just add the location in to the ‘Backup Directory’ under Scheduled Tasks. I have tried that and I don’t see any backup files appearing in the remote directory.

Please note that I am only looking to back up the Plex database and settings, the media is stored somewhere else totally different.

I’m a Linux newbie so please be gentle.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![ChuckPa](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/chuckpa/32/79710_2.png) [@ChuckPa](https://forums.plex.tv/u/ChuckPa)\
**Post date:** [April 9, 2022, 10:45pm UTC](https://forums.plex.tv/t/pms-database-backup-to-external-location-ubuntu/787264/2 "2022-04-09T22:45:53Z")

</div>

There is a very easy way to do this which doesn’t involve a lot of hackery.

1. We setup a script to run at whatever schedule you want.
2. In that script  
a. Stop Plex  
b. Make the full backup of everything (includes any customization of posters, etc)  
c. Start Plex

In that script, you can designate another drive or even on your NAS if you wish; choice is yours.

---

<div class="post-metadata">

**Author:** ![LLundberg](https://avatars.discourse-cdn.com/v4/letter/l/4af34b/32.png) [@LLundberg](https://forums.plex.tv/u/LLundberg)\
**Post date:** [April 9, 2022, 10:59pm UTC](https://forums.plex.tv/t/pms-database-backup-to-external-location-ubuntu/787264/3 "2022-04-09T22:59:12Z")

</div>

Thanks  
I guess I was hoping for a little more detail to get me going i.e. sample script.  
Any chance of that?

---

<div class="post-metadata">

**Author:** ![ChuckPa](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/chuckpa/32/79710_2.png) [@ChuckPa](https://forums.plex.tv/u/ChuckPa)\
**Post date:** [April 9, 2022, 11:41pm UTC](https://forums.plex.tv/t/pms-database-backup-to-external-location-ubuntu/787264/4 "2022-04-09T23:41:56Z")

</div>

Oh sure, I can write you the whole procedure… But what would you learn? 😈

LOL

Key points.

1. Run the script using crontab (as root)
2. In the script (customize/finish as needed):

```auto
#!/bin/bash

# Note: This script assumes running as root in order to make the backup

# Mount NAS folders here if needed (fill in the details)
# mount host:/sharename /mountpoint

# Stop Plex
systemctl stop plexmediaserver

# Perform backup (set the output path from '/nas/backups' to whatever you need)
cd /var/lib/plexmediaserver
tar cf "/nas/backups/PlexBackup-$(date +'%F').tar" ./Library

# All done, start plex
systemctl start plexmediaserver

```

Read up on `crontab`.  
you’ll want `sudo crontab` to edit the `root` user’s crontab jobs file.

The output format for the files will be: `PlexBackup-YYYY-MM-DD.tar`

Will that work?

Note: This is verification of what `date +'%F'` will return

```auto
[chuck@lizum ~.2013]$ date +'%F'
2022-04-09

```

---

<div class="post-metadata">

**Author:** ![LLundberg](https://avatars.discourse-cdn.com/v4/letter/l/4af34b/32.png) [@LLundberg](https://forums.plex.tv/u/LLundberg)\
**Post date:** [April 10, 2022, 1:05am UTC](https://forums.plex.tv/t/pms-database-backup-to-external-location-ubuntu/787264/5 "2022-04-10T01:05:22Z")

</div>

Excellent! That is exactly what I was hoping for. Something to get me started.  
Thanks

---

<div class="post-metadata">

**Author:** ![ChuckPa](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/chuckpa/32/79710_2.png) [@ChuckPa](https://forums.plex.tv/u/ChuckPa)\
**Post date:** [April 10, 2022, 1:14am UTC](https://forums.plex.tv/t/pms-database-backup-to-external-location-ubuntu/787264/6 "2022-04-10T01:14:27Z")

</div>

There are a lot of little tricks there, like `$(command)` . (put any command sequence inside the `()` )

Play with it.

```auto
echo Hi, Today is $(date)

```

Now add

```auto
echo Hi, Today is $(date '%F')
```

---

<div class="post-metadata">

**Author:** ![LLundberg](https://avatars.discourse-cdn.com/v4/letter/l/4af34b/32.png) [@LLundberg](https://forums.plex.tv/u/LLundberg)\
**Post date:** [April 10, 2022, 4:33am UTC](https://forums.plex.tv/t/pms-database-backup-to-external-location-ubuntu/787264/7 "2022-04-10T04:33:37Z")

</div>

Thanks, I think I have some experimenting to do.

---

<div class="post-metadata">

**Author:** ![LLundberg](https://avatars.discourse-cdn.com/v4/letter/l/4af34b/32.png) [@LLundberg](https://forums.plex.tv/u/LLundberg)\
**Post date:** [April 12, 2022, 5:13am UTC](https://forums.plex.tv/t/pms-database-backup-to-external-location-ubuntu/787264/8 "2022-04-12T05:13:31Z")

</div>

Hi,  
I have had a go at this and of course, I am looking for some more advice.

Here is what I did for a script:  
leif@HP-ProLiant-MicroServer:~$ cat pmsbackup-external  
#!/bin/bash

systemctl stop plexmediaserver

cd /var/lib/plexmediaserver  
tar cf 192.168.1.5:/Multimedia/Backup\_files-$(date +’%F’).tar .Library

systemctl start plexmediaserver

Problem No 1:  
Here is what happen when try and run that script:  
leif@HP-ProLiant-MicroServer:~$ pmsbackup-external  
**pmsbackup-external: command not found**

I have to use **sh** to get the script to run. I thought that having the **#!/bin/bash** in the script would fix that?  
Problem No 2: How can I get around the problem with **‘Authentication is required’** if I want to automate this?

Problem No 3: I have created a user ‘leif’ in the NAS but the authentication fails saying ‘Permission Denied’. I have no idea why it says that…I know that this is not Plex related so I am looking for good ideas why this can be? I know that the user is valid, I can log in to the NAS via the web page no problems and that use has Read / Write access to the backup folder.

Thanks heaps in advance…

Leif

leif@HP-ProLiant-MicroServer:~$ sh pmsbackup-external  
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===  
Authentication is required to stop ‘plexmediaserver.service’.  
Multiple identities can be used for authentication:

1. leif, (leif)
2. L Lundberg, (llundberg)  
Choose identity to authenticate as (1-2): 1  
Password:  
==== AUTHENTICATION COMPLETE ===  
[leif@192.168.1.5](mailto:leif@192.168.1.5)’s password:  
Permission denied, please try again.  
[leif@192.168.1.5](mailto:leif@192.168.1.5)’s password:  
Permission denied, please try again.  
[leif@192.168.1.5](mailto:leif@192.168.1.5)’s password:

---

<div class="post-metadata">

**Author:** ![ChuckPa](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/chuckpa/32/79710_2.png) [@ChuckPa](https://forums.plex.tv/u/ChuckPa)\
**Post date:** [April 12, 2022, 5:50am UTC](https://forums.plex.tv/t/pms-database-backup-to-external-location-ubuntu/787264/9 "2022-04-12T05:50:19Z")

</div>

> [@LLundberg](#):
>
> cd /var/lib/plexmediaserver  
> tar cf 192.168.1.5:/Multimedia/Backup\_files-$(date +’%F’).tar .Library

You can’t specify a UNC NFS path like that. Tar doesn’t know what to do with it.

Consider:

```auto
mount 192.168.1.5:/Multimedia /mnt
tar cf /mnt/Backup_files-$(date +’%F’).tar .Library
umount /mnt

```

1. Mount the NFS shared folder `/Multimedia` at the `/mnt` directory (assuming it’s not used)

2. Write the tar backup file

3. Unmount /mnt now that we’re done with it.

===

The ‘command not found’ is because the file isn’t in your PATH string.

The most common solution is to give the full path (e.g.)

`/home/chuck/bin/pmsbackup-external`

-or- (cheating with fancy stuff)

`~/bin/pmsbackup-external`

(the `~` character is a shell shortcut which expands to the path of your home directory. For me, that’s `/home/chuck`. )

study up on adding directories to your PATH variable. It’ll save you typing in the future as you start collecting scripts in `~/bin`😉

For reference, here’s the most common stuff in my `~/bin` that I’ve written for daily use.

```auto
[chuck@lizum ~.2001]$ ls ~/bin
avi2mkv* diff MakeMovies* No-parens* rar* SetEng-mkv* start-pms-syno.zip
backup-wien* dnewpgen* make-mp3* Paulget* rar.d/ setfiles* swipl@
can-read* do-shn* make-sata* perror* rar_static* set-transcoder-debug* swipl-ld@
CheckSize* FindSSDP.py* make-series* pfgw* remount* set-transcoder-error* swipl-win@
CheckSize-slave* get-audio* make-series-binge* pfgwdoc.txt* RemoveYears* set-transcoder-verbose* unrar*
chuck@glock* get-bitrate* make-shn* PlexDBscan* rtrim* sieveit* USB-maker.bin*
clean-episode* get-hdd-temps* make-shn~* pow* rtrim.c snewpgen* vnc*
clear-cache* jfrog* make-specials* pow.c rtrim.o snewpgenlinux.zip* where*
cloud-ui@ make-ape* MediaCodecs pow.o run-llr* speedtest.5 x/
convert-vdi* make-episode* move-if-bigger primo@ run-llr-queue* speedtest.md
CrossVerify* make-german* movie* pyenv@ setdirs* speedtest-x*
des* make-movie* NewPGen.ini* pyenv.d/ seteng-mkv* start-pms-syno*
[chuck@lizum ~.2002]$ 

```

---

<div class="post-metadata">

**Author:** ![LLundberg](https://avatars.discourse-cdn.com/v4/letter/l/4af34b/32.png) [@LLundberg](https://forums.plex.tv/u/LLundberg)\
**Post date:** [April 12, 2022, 6:10am UTC](https://forums.plex.tv/t/pms-database-backup-to-external-location-ubuntu/787264/10 "2022-04-12T06:10:27Z")

</div>

Thank you so much! This GREAT feedback. I think I may have mounted that folder already now that I think about, most likely when I mounted all the media folders.  
Another question; I read somewhere what need to be backed up - /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases.  
Is that not correct? I added the folder that you said which I guess adds a few more sub-folders but otherwise the same.

Thanks again, I will let you know how I go.

---

<div class="post-metadata">

**Author:** ![ChuckPa](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/chuckpa/32/79710_2.png) [@ChuckPa](https://forums.plex.tv/u/ChuckPa)\
**Post date:** [April 12, 2022, 6:46am UTC](https://forums.plex.tv/t/pms-database-backup-to-external-location-ubuntu/787264/11 "2022-04-12T06:46:39Z")

</div>

Backing up the databases and Preferences.xml (file) is the bare minimum.

I always recommend backing up all of “Library” because:

1. It’s easier to restore
2. It’s a full image backup – INCLUDING – any customizations you might make to posters or subtitles or anything else PMS supports.

---

<div class="post-metadata">

**Author:** ![LLundberg](https://avatars.discourse-cdn.com/v4/letter/l/4af34b/32.png) [@LLundberg](https://forums.plex.tv/u/LLundberg)\
**Post date:** [April 12, 2022, 12:59pm UTC](https://forums.plex.tv/t/pms-database-backup-to-external-location-ubuntu/787264/12 "2022-04-12T12:59:16Z")

</div>

Two problems (I think).

Problem 1:  
my file is in /home/leif.  
Here is my PATH:  
leif@HP-ProLiant-MicroServer:~$ echo $PATH  
/home/leif/bin:/home/leif/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/u sr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

Am I missing something?

Problem 2:  
The first step looks like it needs manual intervention, please see below. Can I get around that?  
Authentication is required to stop ‘plexmediaserver.service’.  
Multiple identities can be used for authentication:

1. leif, (leif)
2. L Lundberg, (llundberg)  
Choose identity to authenticate as (1-2): 1  
Password:

Thanks again.

---

<div class="post-metadata">

**Author:** ![LLundberg](https://avatars.discourse-cdn.com/v4/letter/l/4af34b/32.png) [@LLundberg](https://forums.plex.tv/u/LLundberg)\
**Post date:** [April 24, 2022, 5:59am UTC](https://forums.plex.tv/t/pms-database-backup-to-external-location-ubuntu/787264/13 "2022-04-24T05:59:15Z")

</div>

Hi me again,  
I am still working on this script and I have tried to just back up locally first to try and resolve issues with access to the other location.  
I try this:  
leif@HP-ProLiant-MicroServer:~$ sudo systemctl stop plexmediaserver  
[sudo] password for leif:  
leif@HP-ProLiant-MicroServer:~$ tar cf Downloads/plexbu.tar /var/lib/plexmediaserver

And I get this (plus many more ‘Permission denied’, I just copied the first to demonstrate the problem). Why do I get the Permission denied?  
Please help, I have nowhere else to turn.

tar: Removing leading `/’ from member names  
tar: /var/lib/plexmediaserver/Library.old/Application Support/Plex Media Server/Preferences.xml: Cannot open: Permission denied  
tar: /var/lib/plexmediaserver/Library.old/Application Support/Plex Media Server/Cache/CloudAccount.dat: Cannot open: Permission denied  
tar: /var/lib/plexmediaserver/Library.old/Application Support/Plex Media Server/Cache/certificate.p12: Cannot open: Permission denied  
tar: /var/lib/plexmediaserver/Library.old/Application Support/Plex Media Server/Cache/ca.crt: Cannot open: Permission denied  
tar: /var/lib/plexmediaserver/Library.old/Application Support/Plex Media Server/Cache/CloudAccess.dat: Cannot open: Permission denied  
tar: /var/lib/plexmediaserver/Library.old/Application Support/Plex Media Server/Cache/PhotoTranscoder/3c/3c1886943a2e6c6d436cbb57382dbf5d328960e2.jpg: Cannot open: Permission denied  
tar: /var/lib/plexmediaserver/Library.old/Application Support/Plex Media Server/Cache/PhotoTranscoder/80/808129cfc4af9799f73d3bdd55b3d59ef7192d7b.jpg: Cannot open: Permission denied  
tar: /var/lib/plexmediaserver/Library.old/Application Support/Plex Media Server/Cache/PhotoTranscoder/d2/d20a8c1601a1a8facc7b25cb2f3735827a5ba0cc.png: Cannot open: Permission denied  
tar: /var/lib/plexmediaserver/Library.old/Application Support/Plex Media Server/Cache/PhotoTranscoder/dd/dd48254469847a37e81af334403590fb6b815270.jpg: Cannot open: Permission denied  
tar: /var/lib/plexmediaserver/Library.old/Application Support/Plex Media Server/Cache/PhotoTranscoder/c8/c8901481ac00cfedfc4a23133e930a37c2df8459.jpg: Cannot open: Permission denied  
tar: /var/lib/plexmediaserver/Library.old/Application Support/Plex Media Server/Cache/PhotoTranscoder/26/266c02aabb996068fced7a16c03509b1290d881b.jpg: Cannot open: Permission denied  
tar: /var/lib/plexmediaserver/Library.old/Application Support/Plex Media Server/Cache/PhotoTranscoder/a1/a145abbb1d17c835232a38a0929328259b7df774.png: Cannot open: Permission denied  
tar: /var/lib/plexmediaserver/Library.old/Application Support/Plex Media Server/Cache/PhotoTranscoder/7f/7fa8d8cfcfc858ba2f0ce807316a5ce0e4aac14a.jpg: Cannot open: Permission denied  
tar: /var/lib/plexmediaserver/Library.old/Application Support/Plex Media Server/Cache/PhotoTranscoder/f9/f97ac7d1835a4f3a37b19ab76cfeea8e4e4fe733.jpg: Cannot open: Permission denied  
tar: /var/lib/plexmediaserver/Library.old/Application Support/Plex Media Server/Cache/PhotoTranscoder/ab/ab96e8964b94322a84d0f7fd2490bb16259396ac.png: Cannot open: Permission denied  
tar: /var/lib/plexmediaserver/Library.old/Application Support/Plex Media Server/Plug-in Support/Metadata Combination/com.plexapp.agents.lastfm/Artists.xml: Cannot open: Permission denied  
tar: /var/lib/plexmediaserver/Library.old/Application Support/Plex Media Server/Codecs/.device-id: Cannot open: Permission denied  
tar: /var/lib/plexmediaserver/.ssh: Cannot open: Permission denied

---

<div class="post-metadata">

**Author:** ![kegbeach](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/kegbeach/32/216116_2.png) [@kegbeach](https://forums.plex.tv/u/kegbeach)\
**Post date:** [April 24, 2022, 6:12am UTC](https://forums.plex.tv/t/pms-database-backup-to-external-location-ubuntu/787264/14 "2022-04-24T06:12:52Z")

</div>

Probably because PMS was installed with “plex:plex” as the user/group permissions.

If this is the case and you are currently not logged in as “plex” user you can do this:

1. set password for the plex system account:  
sudo -u root passwd plex

2. run the script as user plex:  
sudo -u plex ./scriptname.sh

OR

1. sudo -u root passwd plex
2. su - plex
3. ./scriptname.sh

OR

1. you can add the plex group to your current logged in user:  
sudo -u root usermod -a -G plex YOURCURRENTUSERNAME

2. then as your current logged in user you can run the script.

---

<div class="post-metadata">

**Author:** ![ChuckPa](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/chuckpa/32/79710_2.png) [@ChuckPa](https://forums.plex.tv/u/ChuckPa)\
**Post date:** [April 24, 2022, 6:23am UTC](https://forums.plex.tv/t/pms-database-backup-to-external-location-ubuntu/787264/15 "2022-04-24T06:23:40Z")

</div>

IF I may recommend:

```auto
cd /var/lib/plexmediaserver
sudo bash
systemctl stop plexmediasever
tar cf /path/to/backup.tar ./Library

```

As ROOT, you do not need to alter any system configuration (user `plex`).

Modifying accounts to do the above is not recommended.

> [@Linux Tips](https://forums.plex.tv/t/linux-tips/276247/7):
>
> Backup, Restore, or Clone your PMS installation Backing up your PMS data involves the same steps you’ll need if you were to clone your PMS and take to a new computer, reinstall the operating system, or just want a backup for safe keeping. Making the Backup (General Steps) Stop PMS Invoke the root shell Create the backup image Copy the image to the new system, perform your OS reinstallation, or whatever task you need Restoring a backup image (General Steps) (Re)install PMS itself if on a ne…

---

<div class="post-metadata">

**Author:** ![jhalttu](https://avatars.discourse-cdn.com/v4/letter/j/8e8cbc/32.png) [@jhalttu](https://forums.plex.tv/u/jhalttu)\
**Post date:** [April 24, 2022, 11:52am UTC](https://forums.plex.tv/t/pms-database-backup-to-external-location-ubuntu/787264/16 "2022-04-24T11:52:56Z")

</div>

btw. Will Plex ever allow Backup of all settings and data internally? Ie. to Google drive, etc customers own server. thumbs, settings, and other stuff is not that big data to backup.  
BUT you could make is so that you could backup ALL with checkboxes… just choose what to backup and tell customer that its xxTB of data… =)

---

<div class="post-metadata">

**Author:** ![ChuckPa](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/chuckpa/32/79710_2.png) [@ChuckPa](https://forums.plex.tv/u/ChuckPa)\
**Post date:** [April 24, 2022, 3:17pm UTC](https://forums.plex.tv/t/pms-database-backup-to-external-location-ubuntu/787264/17 "2022-04-24T15:17:21Z")

</div>

@jhalttu

Backing up all of PMS and its data , while it’s running, is very unlikely

I say this because:

1. Backing up a live database, where others could be streaming simultaneously, wouldn’t be a full backup.
2. There are so many different ways and places to backup externally, programming all of them into PMS would be a big task.
3. IF PMS did have the most common backup methods available , we come back to the problem of how to backup a live & operational database.

Bottom line, PMS wasn’t designed to back itself up and doing so would be a big task.  
On some of the platforms, it’s not possible to have it backup itself because of how those OS’s work.

It would be nice but unfortunately it’s not likely to happen because of the amount of work required for such a minimal return.

---

<div class="post-metadata">

**Author:** ![LLundberg](https://avatars.discourse-cdn.com/v4/letter/l/4af34b/32.png) [@LLundberg](https://forums.plex.tv/u/LLundberg)\
**Post date:** [April 25, 2022, 6:47am UTC](https://forums.plex.tv/t/pms-database-backup-to-external-location-ubuntu/787264/18 "2022-04-25T06:47:55Z")

</div>

> [@ChuckPa](#):
>
> ```auto
> cd /var/lib/plexmediaserver
> sudo bash
> systemctl stop plexmediasever
> tar cf /path/to/backup.tar ./Library
> 
> ```

Thanks Chuck, that worked. Much appreciated. One step closer. I hope it is OK for me asking for advice like this.

---

<div class="post-metadata">

**Author:** ![ChuckPa](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/chuckpa/32/79710_2.png) [@ChuckPa](https://forums.plex.tv/u/ChuckPa)\
**Post date:** [April 25, 2022, 7:19am UTC](https://forums.plex.tv/t/pms-database-backup-to-external-location-ubuntu/787264/19 "2022-04-25T07:19:50Z")

</div>

@LLundberg

That’s what we’re here for. I’m glad I could help.

---

<div class="post-metadata">

**Author:** ![LLundberg](https://avatars.discourse-cdn.com/v4/letter/l/4af34b/32.png) [@LLundberg](https://forums.plex.tv/u/LLundberg)\
**Post date:** [May 8, 2022, 6:51am UTC](https://forums.plex.tv/t/pms-database-backup-to-external-location-ubuntu/787264/20 "2022-05-08T06:51:23Z")

</div>

Hi me again, I only seem to get time to work on this occasionally, this is why there are time gaps between my posts.  
I have created a backup folder on the backup server and tried to mount this:

leif@HP-ProLiant-MicroServer:~$ sudo mount 192.168.1.122:/Backup/plex\_backups  
mount.nfs: access denied by server while mounting 192.168.1.122:/Backup/plex\_backups

Any clues why the failure?

I am so grateful for your help here. If it wasn’t for this forum I would be no where with this.

[Next page](https://forums.plex.tv/t/pms-database-backup-to-external-location-ubuntu/787264.md?page=2)
