News for hackers. Stuff that matters.
Re:“Catastrophic” hack wipes out email provider’s entire inf... by benjohnson on Tuesday February 12, 2019 @02:37PM (#19146733)
My experience may shed some light on this: I use pgdump to make backups of an important PostgreSQL server and I thought I was done. Then the server died. I then used the standard import... but it failed. This was a while ago, but pgdump didn't preserve/escape some of the weird quoting in my strings or I (most likely) didn't understand hot to use pgdump properly. I hand to manually figure this out and fix the strings in the file before it would import. If I had tested the full restore, then I would have not have had to panic. Thankfully pgdump didn't throw up it's hands and not emit the strings - they would have been a decent and reasonably sane choice as well. I got lucky.
Re:“Catastrophic” hack wipes out email provider’s entire inf... by luckylion on Tuesday February 12, 2019 @02:42PM (#19146787)
You'd have to test every backup though, because initially, your DB might not contain any strings that trigger the problem.
Re:“Catastrophic” hack wipes out email provider’s entire inf... by sigotirandolas on Tuesday February 12, 2019 @03:05PM (#19146997)
It’s good to test PostgreSQL backups (or basically everything that is constantly doing reads and writes)... some pitfalls in my small experience with a RPi and some cheap SD card:

* If you backup the whole file system while the database is running, you may end up with an inconsistent (maybe unrecoverable?) backup. You need to use a file system with snapshots like ZFS or BTRFS, or use PostgreSQL’s own tools.

* Similarly, if the underlying file system experiments corruption, it will also seem to keep working for a while before, and after that you may be left with a bad database and backup. You have to be able to restore multiple time points or ensure your backup is good.

Re:“Catastrophic” hack wipes out email provider’s entire inf... by DKnoll on Tuesday February 12, 2019 @03:13PM (#19147070)
> * If you backup the whole file system while the database is running, you may end up with an inconsistent (maybe unrecoverable?) backup. You need to use a file system with snapshots like ZFS or BTRFS, or use PostgreSQL’s own tools.

This is true for any sort of mounted database. Always dump the database separately from any FS backups.

Another good idea (but not a replacement for backups) is to replicate the DB to a read-only slave which you can either make the master or recreate your master from.

Re:“Catastrophic” hack wipes out email provider’s entire inf... by chousuke on Tuesday February 12, 2019 @03:39PM (#19147272)
You don't need a SQL dump to backup a PostgreSQL database. It has a mechanism (pg_start_backup) where it will only write WAL (journal) files and will not remove them while you use your filesystem backup (eg. rsync) as usual until you signal completion (pg_stop_backup), after which you also need to back up your WAL archive.

This gives you everything you need to recover to any point between the start and stop of the backup operation, and it's guaranteed to be consistent assuming the data itself was copied successfully. This is because any inconsistent files modified during the copy will be recovered from the archived WAL files to attain a consistent state.

Re:“Catastrophic” hack wipes out email provider’s entire inf... by AznHisoka on Tuesday February 12, 2019 @03:27PM (#19147172)
How did you know if the pg_dump finished running? In my experience, there doesn't seem to be any way to find out if it finished, or exited prematurely. The only hack I came up with is to write the output to a log, and then grep the log for the last alphabetical table, and ensure it was in the log. That usually meant it backed up all the tables.
Re:“Catastrophic” hack wipes out email provider’s entire inf... by adamzochowski on Tuesday February 12, 2019 @11:19PM (#19150381)
pg_dump provides return codes just like any other executable. Zero means no error, and treat non-zero value as an error.
Re:“Catastrophic” hack wipes out email provider’s entire inf... by rob-olmos on Tuesday February 12, 2019 @04:29PM (#19147721)
IIRC mysqldump had a similar issue back in the day before the --quoted-names option became enabled by default.