# Regarding Chucks Tips & Trick - Backup

**URL:** <https://forums.plex.tv/t/regarding-chucks-tips-trick-backup/363545>\
**Category:** General Discussions\
**Tags:** server-linux\
**Created:** [January 17, 2019, 12:35pm UTC](https://forums.plex.tv/t/regarding-chucks-tips-trick-backup/363545 "2019-01-17T12:35:04Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Morphy](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/morphy/32/11124_2.png) [@Morphy](https://forums.plex.tv/u/Morphy)\
**Post date:** [January 17, 2019, 12:35pm UTC](https://forums.plex.tv/t/regarding-chucks-tips-trick-backup/363545/1 "2019-01-17T12:35:04Z")

</div>

@ChuckPa

Hi Chuck

Regarding your Tips & Tricks:

> [@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…

I have rewritten a script I found on a forum to my own needs working with rclone to googledrive.

In short term what it does it. After a new Ubuntu 16.04LTS install I execute my script. It install all the current programs I have running on the server. It downloads the scripts I have encrypted on my googledrive, ssh keys … scripts , configs… everything. Maybe not the BEST script , and the best way of doing it 🙂 , but its working for me as it should . ( My first modifed script so… )

> <https://gist.github.com/MorphyDK/946aaabbc0384537667e8ebfa3e06c07>

But im kinda missing a backup / restore function to Plex.

I want to implement your guide to my script .  
Lets say I want to have the script called plexbackup.sh I can run via crontab.

#!/bin/bash  
sudo systemctl stop plexmediaserver.service  
cd /var/lib/plexmediaserver  
sudo tar cfz /nas/tmp/PlexBackup.tar.gz ./Library  
echo “Backup of Plexmediaserver is complete”

Would that work for the backup? I know you wrote root shell, but will this work when im logged in as user and executing the script?

Then I will have the restore script made as well,but that script needs to be execute in my Install.sh script 🙂

I had some server crashes over time, so I wanted to make a script that reinstall my entire server as it was before it died 🙂 .

Thanks

Morphy

---

<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:** [January 17, 2019, 4:47pm UTC](https://forums.plex.tv/t/regarding-chucks-tips-trick-backup/363545/2 "2019-01-17T16:47:04Z")

</div>

Very simple little functions. Error handling needs adding

**Backup:**

```auto
systemctl stop plexmediaserver
sleep 5
cd /var/lib/plexmediaserver
tar cf ${BackupDir}/PlexBackup.tar ./Library
systemctl start plexmediaserver

```

**Restore:**

```auto
systemctl stop plexmediserver
sleep 5
cd /var/lib/plexmediaserver
mv Library Library.old

tar xf ${BackupDir}/PlexBackup.tar
chown -R plex:plex ./Library &
find . -type d -exec chmod 755 {} \; &
find . -type f -exec chmod 644 {} \; &
wait
systemctl start plexmediaserver

```

Will this do?

---

<div class="post-metadata">

**Author:** ![Morphy](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/morphy/32/11124_2.png) [@Morphy](https://forums.plex.tv/u/Morphy)\
**Post date:** [January 17, 2019, 5:34pm UTC](https://forums.plex.tv/t/regarding-chucks-tips-trick-backup/363545/3 "2019-01-17T17:34:17Z")

</div>

Hi ChuckPA 🙂

Looks good 🙂

THANK you very much

Gonna test

Thanks

Morphy

---

<div class="post-metadata">

**Author:** ![Morphy](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/morphy/32/11124_2.png) [@Morphy](https://forums.plex.tv/u/Morphy)\
**Post date:** [January 17, 2019, 5:43pm UTC](https://forums.plex.tv/t/regarding-chucks-tips-trick-backup/363545/4 "2019-01-17T17:43:30Z")

</div>

> [@ChuckPa](#):
>
> systemctl start plexmediaserver

Oh will it backup all the user share folder access as well?

---

<div class="post-metadata">

**Author:** ![OttoKerner](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/ottokerner/32/10079_2.png) [@OttoKerner](https://forums.plex.tv/u/OttoKerner)\
**Post date:** [January 17, 2019, 5:49pm UTC](https://forums.plex.tv/t/regarding-chucks-tips-trick-backup/363545/5 "2019-01-17T17:49:16Z")

</div>

> [@Morphy](#):
>
> Oh will it backup all the user share folder access as well?

That information lives on plex.tv  
And it is tied to the machine ID, which is stored in the `Preferences.xml`  
which should already be covered by the backup script, if I read it correctly.

---

<div class="post-metadata">

**Author:** ![Morphy](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/morphy/32/11124_2.png) [@Morphy](https://forums.plex.tv/u/Morphy)\
**Post date:** [January 17, 2019, 5:51pm UTC](https://forums.plex.tv/t/regarding-chucks-tips-trick-backup/363545/6 "2019-01-17T17:51:25Z")

</div>

> [@ChuckPa](#):
>
> tar cf ${BackupDir}/PlexBackup.tar ./Library

Ty OttoKerner 🙂  
May I ask what tar cf ${BackupDir}/PlexBackup.tar ./Library does?

Do I need to put in my path lets say /home/plex/Backup to

tar cf ${/home/plex/Backup}/PlexBackup.tar ./Library ?

---

<div class="post-metadata">

**Author:** ![OttoKerner](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/ottokerner/32/10079_2.png) [@OttoKerner](https://forums.plex.tv/u/OttoKerner)\
**Post date:** [January 17, 2019, 5:52pm UTC](https://forums.plex.tv/t/regarding-chucks-tips-trick-backup/363545/7 "2019-01-17T17:52:23Z")

</div>

Sorry, I don’t understand this in detail. (not a Linux guy here)  
@ChuckPa will know that

---

<div class="post-metadata">

**Author:** ![Morphy](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/morphy/32/11124_2.png) [@Morphy](https://forums.plex.tv/u/Morphy)\
**Post date:** [January 17, 2019, 5:53pm UTC](https://forums.plex.tv/t/regarding-chucks-tips-trick-backup/363545/8 "2019-01-17T17:53:13Z")

</div>

Well I know its tar which is used to backup, but i dont understand the backup thingy 🙂

---

<div class="post-metadata">

**Author:** ![OttoKerner](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/ottokerner/32/10079_2.png) [@OttoKerner](https://forums.plex.tv/u/OttoKerner)\
**Post date:** [January 17, 2019, 6:01pm UTC](https://forums.plex.tv/t/regarding-chucks-tips-trick-backup/363545/9 "2019-01-17T18:01:24Z")

</div>

`man tar` would’ve been the answer in some other forums 😉 .  
But that should at least give you an idea about the `cf` parameter

`./Library` means AFAIK “go one level up in the folder structure” `./` and then dive down into the subfolder `Library`  
(but I could be absolutely wrong 😅 )

---

<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:** [January 17, 2019, 6:16pm UTC](https://forums.plex.tv/t/regarding-chucks-tips-trick-backup/363545/10 "2019-01-17T18:16:59Z")

</div>

If I may teach a little bit about “dot” and “dot dot” ? 🤣

Dot and DotDot are “current directory relative” addressing shortcuts.  
“dot” ( **.** ) - this, the current, directory.  
“dot dot” ( **…** ) - this directory’s parent directory.

Using **./Library** notation is largely for **tar** ’s benefit.  
Looking inside the tar file, all the names will begin with **./**  
This guarantees all the files are rooted in the new ‘current’ directory when extracting.

Primary example of how this “slides uphill” 🙂

```auto
cd /var/lib/plexmediaserver 
tar cf - ./Library | ( cd /home/plexdata ; tar xf - )

```

What does that do?

1. sets the current directory to “/var/lib/plexmediaserver”
2. In one command it:  
a. Creates a tar file but, instead of writing to a named file, sends it to **stdout**  
b. Creates a pipe to connect the **stdout** of the first part to the **stdin** of the second part  
c. The second part spawns a subshell which executes two commands: Change directory & extracts from the tar file being streamed through **stdin**

The TL;DR - It is the fastest and easiest way to clone your entire Plex metadata library to a new location ( **/home/plexdata** in this case)

Follow this path?

**/var/lib/plexmediaserver/…/…/…/etc/systemd/system/plexmediaserver.service.d**

Where are we?

1. Starting in /var/lib/plexmediaserver
2. Go up 3 directories (to the root)
3. Continue by going down into etc
4. End up in **/etc/systemd/system/plexmediaserver**

---

<div class="post-metadata">

**Author:** ![OttoKerner](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/ottokerner/32/10079_2.png) [@OttoKerner](https://forums.plex.tv/u/OttoKerner)\
**Post date:** [January 17, 2019, 6:21pm UTC](https://forums.plex.tv/t/regarding-chucks-tips-trick-backup/363545/11 "2019-01-17T18:21:57Z")

</div>

There you go, as I assumed I was absolutely wrong! 😉

---

<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:** [January 17, 2019, 6:24pm UTC](https://forums.plex.tv/t/regarding-chucks-tips-trick-backup/363545/12 "2019-01-17T18:24:49Z")

</div>

Windows and MacOS also use this (surprisingly)

These shortcuts had their roots in Multics because, in those days, teletype machines were “beyond painful” to type on. We needed an easier way. “Dot” and “Dot Dot” were the answer.

Unix came from Multics  
BSD Unix came unto being when AT&T couldn’t get Unix version 4 done in time & on budget  
MS-DOS borrowed from Unix.  
MacOS is rooted in BSD Unix.  
Linux is the ‘fresh free spin’ of the entire OS without the entire AT&T encumbrance

---

<div class="post-metadata">

**Author:** ![Morphy](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/morphy/32/11124_2.png) [@Morphy](https://forums.plex.tv/u/Morphy)\
**Post date:** [January 17, 2019, 6:51pm UTC](https://forums.plex.tv/t/regarding-chucks-tips-trick-backup/363545/13 "2019-01-17T18:51:26Z")

</div>

Jesus Christ … i need to learn a bit more of this 🙂

Ty for explaining to the both of you .

I probably need to read this a couple of times to understand it fully 🙂

---

<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:** [January 17, 2019, 7:38pm UTC](https://forums.plex.tv/t/regarding-chucks-tips-trick-backup/363545/14 "2019-01-17T19:38:34Z")

</div>

This is what happens when you and the dinosaurs were on a first-name basis  
🤣

---

<div class="post-metadata">

**Author:** ![Morphy](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/morphy/32/11124_2.png) [@Morphy](https://forums.plex.tv/u/Morphy)\
**Post date:** [January 17, 2019, 8:24pm UTC](https://forums.plex.tv/t/regarding-chucks-tips-trick-backup/363545/15 "2019-01-17T20:24:49Z")

</div>

😝😁

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/plex/original/3X/2/a/2acb9765406f63293d357b4ec509ec39aa28f2ad.png) [@system](https://forums.plex.tv/u/system)\
**Post date:** [April 17, 2019, 8:24pm UTC](https://forums.plex.tv/t/regarding-chucks-tips-trick-backup/363545/16 "2019-04-17T20:24:54Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
