Regarding Chucks Tips & Trick - Backup

@ChuckPa

Hi Chuck

Regarding your Tips & Tricks:

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 :slight_smile: , but its working for me as it should . ( My first modifed script so… )

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 :slight_smile:

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 :slight_smile: .

Thanks

Morphy

1 Like

Very simple little functions. Error handling needs adding

Backup:

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

Restore:

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?

1 Like

Hi ChuckPA :slight_smile:

Looks good :slight_smile:

THANK you very much

Gonna test

Thanks

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.

Ty OttoKerner :slight_smile:
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 ?

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

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

man tar would’ve been the answer in some other forums :wink: .
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 :sweat_smile: )

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

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” :slight_smile:

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

There you go, as I assumed I was absolutely wrong! :wink:

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

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

Ty for explaining to the both of you .

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

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

:stuck_out_tongue_closed_eyes::grin:

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