Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync between a bare metal install and a backup docker install #24

Open
geek-baba opened this issue Apr 15, 2020 · 12 comments
Open

Sync between a bare metal install and a backup docker install #24

geek-baba opened this issue Apr 15, 2020 · 12 comments

Comments

@geek-baba
Copy link

geek-baba commented Apr 15, 2020

I am not sure if its possible or not but I would like to setup a backup server in docker and bare metal as my primary. Any example that would be great in the wiki section.

@goofballtech
Copy link

I know the reason i had not answered before was because i don't know what "bare metal" means as far as a configuration is concerned. The readme does pretty good as giving general instruction of how to get the syncing to work via ssh. If you can give a bit more data though i will attempt to assist you in getting it working.

@geek-baba
Copy link
Author

I am so sorry I was not clear, bare-metal meaning ubuntu 18.04 server installed on a physical Dell Server that is running plexserver, the other plexserver (docker) is running on another server that is running Debian 10 and Docker.

The concern I had how to perform start stop for each and where to run this, on Ubuntu server or run it as docker.

@goofballtech
Copy link

goofballtech commented Jun 8, 2020

it can be run from either side. You first need to decide where you want it to run and set up the commands for server 1 and server 2 appropriately. So the server that you run sync on will be local command like "docker stop plex" or similar and the remote server will be "ssh -oStrictHostKeyChecking=no -i /keys/serverkey [email protected] service plexmediaserver stop" which gives docker on the remote machine a stop command via an ssh command using a locally stored RSA key for authentication.

So you have to decide which computer you want to enable ssh on and get a key set up for connecting properly then build up the syncing commands from there.

Do some local testing at the command line on your own. Once you have the start and stop working remotely via a single command it shouldn't be too hard to plug them into the run command for this script.

*edit - fix fat fingering from typing on phone

@geek-baba
Copy link
Author

geek-baba commented Jun 10, 2020

Thanks for the examples, so I decided to try to run as docker, here is my docker create command:

docker create
--name=plex-db-sync
-v /etc/localtime:/etc/localtime:ro
-v /home/k8s/config/.ssh:/sshkey
-v /home/k8s/config/plex/Library/Application Support/Plex Media Server/Plug-in Support/Databases/:/mnt/DB2
-e CRON=0 4 * * *
-e S1_SSH_KEY=/sshkey
-e S1_SSH_USER=k8s
-e S1_SSH_HOST=10.10.10.20
-e S1_SSH_PORT=22
-e S1_SSH_PATH=/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases
-e S1_START=ssh -oStrictHostKeyChecking=no -i /sshkey [email protected] 'sudo service plexmediaserver start'
-e S1_STOP=ssh -oStrictHostKeyChecking=no -i /sshkey [email protected] 'sudo service plexmediaserver stop'
-e S2_DB_PATH=/mnt/DB2
-e S2_START=docker start plex
-e S2_STOP=docker stop plex
--restart always
nowsci/plex-db-sync

However I am getting the error : invalid reference format: repository name must be lowercase

@goofballtech
Copy link

goofballtech commented Jun 10, 2020

In script world a space means "move on to the next potential command".
Anything you have with a space in it should be contained in quotes.

edit, adding \ to each line end to allow the new line breaks

docker create \
--name=plex-db-sync \
-v /etc/localtime:/etc/localtime:ro \
-v /home/k8s/config/.ssh:/sshkey \
-v "/home/k8s/config/plex/Library/Application Support/Plex Media Server/Plug-in Support/Databases/:/mnt/DB2" \
-e CRON="0 4 * * *" \
-e S1_SSH_KEY=/sshkey \
-e S1_SSH_USER=k8s \
-e S1_SSH_HOST=10.10.10.20 \
-e S1_SSH_PORT=22 \
-e S1_SSH_PATH="/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases" \
-e S1_START="ssh -oStrictHostKeyChecking=no -i /sshkey [email protected] 'sudo service plexmediaserver start'" \
-e S1_STOP="ssh -oStrictHostKeyChecking=no -i /sshkey [email protected] 'sudo service plexmediaserver stop'" \
-e S2_DB_PATH=/mnt/DB2 \
-e S2_START="docker start plex" \
-e S2_STOP="docker stop plex" \
--restart always \
nowsci/plex-db-sync

@geek-baba
Copy link
Author

yeah i used the same command, the backward slash was lost since i did not use the insert code while pasting the command. also if you just paste it, it would throw a different error:
`"docker create" requires at least 1 argument.
See 'docker create --help'.

Usage: docker create [OPTIONS] IMAGE [COMMAND] [ARG...]

Create a new container
-bash: --name=plex-db-sync: command not found
-bash: -v: command not found
-bash: -v: command not found
-bash: -v: command not found
-bash: -e: command not found
-bash: -e: command not found
-bash: -e: command not found
-bash: -e: command not found
-bash: -e: command not found
-bash: -e: command not found
-bash: -e: command not found
-bash: -e: command not found
-bash: -e: command not found
-bash: -e: command not found
-bash: -e: command not found
-bash: --restart: command not found
-bash: nowsci/plex-db-sync: No such file or directory`

@goofballtech
Copy link

when i copy and paste it i get

 ✘ ✝  ~  sudo docker create \
--name=plex-db-sync \
-v /etc/localtime:/etc/localtime:ro \
-v /home/k8s/config/.ssh:/sshkey \
-v "/home/k8s/config/plex/Library/Application Support/Plex Media Server/Plug-in Support/Databases/:/mnt/DB2" \
-e CRON="0 4 * * *" \
-e S1_SSH_KEY=/sshkey \
-e S1_SSH_USER=k8s \
-e S1_SSH_HOST=10.10.10.20 \
-e S1_SSH_PORT=22 \
-e S1_SSH_PATH="/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases" \
-e S1_START="ssh -oStrictHostKeyChecking=no -i /sshkey [email protected] 'sudo service plexmediaserver start'" \
-e S1_STOP="ssh -oStrictHostKeyChecking=no -i /sshkey [email protected] 'sudo service plexmediaserver stop'" \
-e S2_DB_PATH=/mnt/DB2 \
-e S2_START="docker start plex" \
-e S2_STOP="docker stop plex" \
--restart always \
nowsci/plex-db-sync          
[sudo] password for goofballtech: 
Unable to find image 'nowsci/plex-db-sync:latest' locally
latest: Pulling from nowsci/plex-db-sync
df20fa9351a1: Pull complete 
8b40b9cc6c1b: Pull complete 
e6b675d49c8a: Pull complete 
484a8d43f281: Pull complete 
c67ea66619a4: Pull complete 
Digest: sha256:cf296d572bbaa6880cb35cafab396b2a1095f0b55c00a2bbd94dbda06471ad5a
Status: Downloaded newer image for nowsci/plex-db-sync:latest
19a47c1b9c482584d06cd47bd6eb4ceab4334a321681ceb28621c654cbd0757c
 ✝  ~  

@geek-baba
Copy link
Author

It worked for me too! Must be a format issue or something, thank you! Now to test if it works...

@geek-baba
Copy link
Author

ok after testing this is what I get from the docker shell:
bash-5.0# ssh -oStrictHostKeyChecking=no -i /sshkey [email protected] 'sudo service plexmediaserver start' load pubkey "/sshkey": Is a directory @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: UNPROTECTED PRIVATE KEY FILE! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Permissions 0755 for '/sshkey' are too open. It is required that your private key files are NOT accessible by others. This private key will be ignored. Load key "/sshkey": bad permissions [email protected]'s password:

@goofballtech
Copy link

Seems pretty obvious by the error that ssh wont let you load a key from a file that has incorrect permissions. Research the error and someone will have said what the permissions need to be then you can change permissions on the file appropriately and try again.

@geek-baba
Copy link
Author

Ok - finally got some time to fix the permissions and was able to start and stop plex server from docker container manually. I assume the script is set to run 4AM local time, do I need to prepare the plex servers before the sync happens? I have backed up the main plex library that is running on Ubuntu 18.04, anything else I need to worry about?

@geek-baba
Copy link
Author

geek-baba commented Jun 14, 2020

Close but no cigar...now db access issues:

[Sun Jun 14 14:09:37 EDT 2020] Mounting sshfs for server 1...,
[Sun Jun 14 14:09:38 EDT 2020] Starting.,
[Sun Jun 14 14:09:38 EDT 2020] TMPFOLDER: /tmp/plex-db-sync,
[Sun Jun 14 14:09:38 EDT 2020] DEBUG: true,
[Sun Jun 14 14:09:38 EDT 2020] PLEXDB1: /mnt/S1/com.plexapp.plugins.library.db,
[Sun Jun 14 14:09:38 EDT 2020] PLEXDB2: /mnt/DB2/com.plexapp.plugins.library.db,
[Sun Jun 14 14:09:38 EDT 2020] PLEXSTART1: ssh -oStrictHostKeyChecking=no -i /sshkey [email protected] 'sudo service plexmediaserver start',
[Sun Jun 14 14:09:38 EDT 2020] PLEXSTOP1: ssh -oStrictHostKeyChecking=no -i /sshkey [email protected] 'sudo service plexmediaserver stop',
[Sun Jun 14 14:09:38 EDT 2020] PLEXSTART2: docker start plex,
[Sun Jun 14 14:09:38 EDT 2020] PLEXSTOP2: docker stop plex,
[Sun Jun 14 14:09:38 EDT 2020] PLEXF1: /tmp/plex-db-sync/1.sql,
[Sun Jun 14 14:09:38 EDT 2020] PLEXF2: /tmp/plex-db-sync/2.sql,
[Sun Jun 14 14:09:38 EDT 2020] TMPDB: /tmp/plex-db-sync/tmp.db,
[Sun Jun 14 14:09:38 EDT 2020] IGNORE: ,
[Sun Jun 14 14:09:38 EDT 2020] IGNORESTR: ,
[Sun Jun 14 14:09:38 EDT 2020] BACKUP: false,
[Sun Jun 14 14:09:38 EDT 2020] version db1: 20200515172900  db2: 20200515172900,
[Sun Jun 14 14:09:38 EDT 2020] Stopping Plex on Server 1... Done,
[Sun Jun 14 14:09:39 EDT 2020] Stopping Plex on Server 2... Done,
Error: near line 1: attempt to write a readonly database,
[Sun Jun 14 14:09:42 EDT 2020] Checking for changes... [Sun Jun 14 14:09:42 EDT 2020] UP1:  - UP2: 2020-05-22 08:22:39,
Found,
Error: attempt to write a readonly database,
Error: attempt to write a readonly database,
Error: attempt to write a readonly database,
Error: attempt to write a readonly database,
Error: attempt to write a readonly database,
Error: attempt to write a readonly database,
Error: attempt to write a readonly database,
Error: attempt to write a readonly database,
Error: near line 1: attempt to write a readonly database,
Error: near line 1: no such table: tmpdb.metadata_item_settings2,
[Sun Jun 14 14:09:42 EDT 2020] Processing tags...,
[Sun Jun 14 14:09:42 EDT 2020] -=-: select distinct t1.* from taggings1 ts1, tags1 t1, metadata_items1 m1 where ts1.tag_id=t1.id and ts1.metadata_item_id=m1.id and t1.tag_type=11 and m1.guid in (select guid from metadata_items2) and t1.tag not in (select tag from tags2);,
Error: no such table: taggings1,
[Sun Jun 14 14:09:42 EDT 2020] -=-: select ts1.*, t1.tag, m1.guid from taggings1 ts1, tags1 t1, metadata_items1 m1 where ts1.tag_id=t1.id and ts1.metadata_item_id=m1.id and t1.tag_type=11 and m1.guid in (select guid from metadata_items2) and m1.guid not in (select distinct m2.guid from taggings2 ts2, tags2 t2, metadata_items2 m2 where ts2.tag_id=t2.id and ts2.metadata_item_id=m2.id and t2.tag_type=11 and t2.tag=t1.tag);,
Error: no such table: taggings1,
[Sun Jun 14 14:09:42 EDT 2020] -=-: select distinct t2.* from taggings2 ts2, tags2 t2, metadata_items2 m2 where ts2.tag_id=t2.id and ts2.metadata_item_id=m2.id and t2.tag_type=11 and m2.guid in (select guid from metadata_items1) and t2.tag not in (select tag from tags1);,
Error: no such table: taggings2,
[Sun Jun 14 14:09:42 EDT 2020] -=-: select ts2.*, t2.tag, m2.guid from taggings2 ts2, tags2 t2, metadata_items2 m2 where ts2.tag_id=t2.id and ts2.metadata_item_id=m2.id and t2.tag_type=11 and m2.guid in (select guid from metadata_items1) and m2.guid not in (select distinct m1.guid from taggings1 ts1, tags1 t1, metadata_items1 m1 where ts1.tag_id=t1.id and ts1.metadata_item_id=m1.id and t1.tag_type=11 and t1.tag=t2.tag);,
Error: no such table: taggings2,
[Sun Jun 14 14:09:42 EDT 2020] -=-: select id, name from accounts where lower(name) not in () order by id;,
Error: attempt to write a readonly database,
/plex-db-sync: line 417: declare: `-A': not a valid identifier,
[Sun Jun 14 14:09:42 EDT 2020] -=-: select id, name from accounts where lower(name) not in () order by id;,
[Sun Jun 14 14:09:45 EDT 2020] Starting Plex on Server 1... Done,
[Sun Jun 14 14:09:46 EDT 2020] Starting Plex on Server 2... Done,
[Sun Jun 14 14:09:46 EDT 2020] Finished.,
[Sun Jun 14 14:09:46 EDT 2020] Setting up cron.,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants