Difference between revisions of "2018/01/14"

From Mew
Jump to navigation Jump to search
(rearranged order slightly)
(saving work)
Line 25: Line 25:
  
 
...or, rather: <code>createdb --owner=tootcat tootcat-masto-r1</code> -- except do I need to create "tootcat" as a system user first? Or a db user?
 
...or, rather: <code>createdb --owner=tootcat tootcat-masto-r1</code> -- except do I need to create "tootcat" as a system user first? Or a db user?
 +
===Work Log===
 +
====step 1====
 +
Created user and group "tootcat" with /bin/bash as shell, no login allowed. I checked user "polymerwitch" (user for ''current'' Mastodon instance), and it has "sudo" membership -- but I'm not adding that, because it shouldn't be needed.
 +
====step 2====
 +
: <code>root@tootcat:~# '''createdb --owner=tootcat tootcat-masto-r1'''</code>
 +
:: <code>createdb: could not connect to database template1: FATAL:  role "root" does not exist</code>
 +
::: Apparently pg assumes whatever the current system user is as its internal user as well.
 +
: <code>root@tootcat:~# '''su - postgres -c 'createdb --owner=tootcat tootcat-masto-r1''''</code>
 +
:: <code>createdb: database creation failed: ERROR:  role "tootcat" does not exist</code>
 +
: <code>root@tootcat:~# '''createuser --createdb tootcat'''</code>
 +
:: <code>createuser: could not connect to database postgres: FATAL:  role "root" does not exist</code> - can't say I'm surprised
 +
: <code>root@tootcat:~# '''su - postgres -c 'createuser --createdb tootcat''''</code>
 +
:: Success.
 +
: <code>root@tootcat:~# '''su - postgres -c 'createdb --owner=tootcat tootcat-masto-r1''''</code>
 +
:: Success.
 +
====step 3====
 +
[https://www.postgresql.org/docs/current/static/backup-dump.html Importing the data dump] into the new db:
 +
: <code>root@tootcat:~# '''cd /root/scratch'''</code>
 +
: <code>root@tootcat:~/scratch# '''ls'''</code>
 +
:: <code>tootcat.sql</code>
 +
: <code>root@tootcat:~/scratch# '''psql tootcat-masto-r1 < tootcat.sql'''</code>
 +
:: <code>psql: FATAL:  role "root" does not exist</code>
 +
::: I actually expected this, but just wanted to make sure.
 +
: <code>root@tootcat:~/scratch# '''su - postgres -c 'psql tootcat-masto-r1 < tootcat.sql'''</code>
 +
:: <code>-su: tootcat.sql: No such file or directory</code>
 +
::: Apparently this operates relative to the <code>postgres</code> user's home folder, or wherever you get put by default when logging in. Okay.
 +
: <code>root@tootcat:~/scratch# '''su - postgres -c 'psql tootcat-masto-r1 < /root/scratch/tootcat.sql''''</code>
 +
:: <code>-su: /root/scratch/tootcat.sql: Permission denied</code>
 +
::: This is also unsurprising. Other users shouldn't have access to /root files.
 +
 +
It was more or less at this point that I discovered that the <code>tootcat.sql</code> file was zero bytes long, so apparently the export process wasn't happy either.
 +
 +
There's no <code>/home/postgres</code>, so we can't go there.
 +
 +
<code>/root/scratch</code> is already mode 777, so apparently that's insufficient.
 +
 +
Oh, but the ''actual'' <code>tootcat.sql</code> file is in <code>/root/backups</code>. Just to be sure, then:
 +
 +
: <code>root@tootcat:~/scratch# '''cd ../backups/'''</code>
 +
: <code>root@tootcat:~/backups# '''su - postgres -c 'psql tootcat-masto-r1 < /root/backups/tootcat.sql''''</code>
 +
:: <code>-su: /root/backups/tootcat.sql: Permission denied</code>
 +
::: As expected.
 +
 +
And then it finally occurred to me:
 +
: <code>root@tootcat:~/backups# '''su - postgres -c 'pwd''''</code>
 +
:: <code>/var/lib/postgresql</code>
 +
::: Oh! Sneaksy, having a home folder outside of the <code>/home</code> folder. Just because <code>/root</code> does it doesn't make it okay; do as I say, not as I do....
 +
: <code>root@tootcat:~/backups# '''cd /var/lib/postgresql/'''</code>
 +
: <code>root@tootcat:/var/lib/postgresql# '''mv /root/backups/tootcat.sql ./'''</code>
 +
: <code>root@tootcat:/var/lib/postgresql# '''chown postgres:postgres tootcat.sql'''</code>
 +
: <code>root@tootcat:/var/lib/postgresql# '''su - postgres -c 'psql tootcat-masto-r1 < tootcat.sql''''</code>
 +
:: ...and then stuff started happening that ''might'' have been the output of a successful import.

Revision as of 19:37, 14 January 2018

2018-01-14

My current plan is:

  1. create new system user "tootcat"
  2. create a new Postgres db for toot.cat's Mastodon
  3. migrate the data there
  4. install Mastodon under user "tootcat"
  5. run Mastodon's schema upgrade rake task
  6. test the result as https://new.toot.cat (get it working)
  7. write a script to automate the data migration
  8. in close succession:
    1. run the migration script
    2. reconfigure nginx to point to the new instance

revisions

  • Decided it would simplify things if I went ahead and created the "tootcat" system user first.

Notes

Inside /root/backups:

su - postgres -c 'pg_dump mastodon' > tootcat.sql

Upgrading Mastodon: official

I'm calling the new db tootcat-masto-r1 (toot.cat Mastodon db revision 1) (possibly with '-' replaced by '_').

Probably just need to do this next: CREATE DATABASE tootcat-masto-r1;

...or, rather: createdb --owner=tootcat tootcat-masto-r1 -- except do I need to create "tootcat" as a system user first? Or a db user?

Work Log

step 1

Created user and group "tootcat" with /bin/bash as shell, no login allowed. I checked user "polymerwitch" (user for current Mastodon instance), and it has "sudo" membership -- but I'm not adding that, because it shouldn't be needed.

step 2

root@tootcat:~# createdb --owner=tootcat tootcat-masto-r1
createdb: could not connect to database template1: FATAL: role "root" does not exist
Apparently pg assumes whatever the current system user is as its internal user as well.
root@tootcat:~# su - postgres -c 'createdb --owner=tootcat tootcat-masto-r1'
createdb: database creation failed: ERROR: role "tootcat" does not exist
root@tootcat:~# createuser --createdb tootcat
createuser: could not connect to database postgres: FATAL: role "root" does not exist - can't say I'm surprised
root@tootcat:~# su - postgres -c 'createuser --createdb tootcat'
Success.
root@tootcat:~# su - postgres -c 'createdb --owner=tootcat tootcat-masto-r1'
Success.

step 3

Importing the data dump into the new db:

root@tootcat:~# cd /root/scratch
root@tootcat:~/scratch# ls
tootcat.sql
root@tootcat:~/scratch# psql tootcat-masto-r1 < tootcat.sql
psql: FATAL: role "root" does not exist
I actually expected this, but just wanted to make sure.
root@tootcat:~/scratch# su - postgres -c 'psql tootcat-masto-r1 < tootcat.sql
-su: tootcat.sql: No such file or directory
Apparently this operates relative to the postgres user's home folder, or wherever you get put by default when logging in. Okay.
root@tootcat:~/scratch# su - postgres -c 'psql tootcat-masto-r1 < /root/scratch/tootcat.sql'
-su: /root/scratch/tootcat.sql: Permission denied
This is also unsurprising. Other users shouldn't have access to /root files.

It was more or less at this point that I discovered that the tootcat.sql file was zero bytes long, so apparently the export process wasn't happy either.

There's no /home/postgres, so we can't go there.

/root/scratch is already mode 777, so apparently that's insufficient.

Oh, but the actual tootcat.sql file is in /root/backups. Just to be sure, then:

root@tootcat:~/scratch# cd ../backups/
root@tootcat:~/backups# su - postgres -c 'psql tootcat-masto-r1 < /root/backups/tootcat.sql'
-su: /root/backups/tootcat.sql: Permission denied
As expected.

And then it finally occurred to me:

root@tootcat:~/backups# su - postgres -c 'pwd'
/var/lib/postgresql
Oh! Sneaksy, having a home folder outside of the /home folder. Just because /root does it doesn't make it okay; do as I say, not as I do....
root@tootcat:~/backups# cd /var/lib/postgresql/
root@tootcat:/var/lib/postgresql# mv /root/backups/tootcat.sql ./
root@tootcat:/var/lib/postgresql# chown postgres:postgres tootcat.sql
root@tootcat:/var/lib/postgresql# su - postgres -c 'psql tootcat-masto-r1 < tootcat.sql'
...and then stuff started happening that might have been the output of a successful import.