[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to clone a dataset?



On Sun, 28 Sep 2008 18:16:24 +1000, david wrote:

> I want to create a clone of a dataset except with a different dataset name and 
> different users. Both versions need to be "live" simultaneously.

I use convenience scripts to quickly and consistently backup and restore
from the command line in plaintext format. This plaintext representation
of the database is under version control (git, bzr, hg, svn, etc.), so
there's no worry about overwriting old backups:

$ cat backupdb.sh 
pg_dump --format=p -c --encoding=UTF8 -U postgres mycompany --file=mycompany.sql

$ cat restoredb.sh 
psql -U postgres -d mycompany -f mycompany.sql

For a test/staging environment, you can simply create a new db:

$ createdb -U postgres mysandbox

and restore your backup to the sandbox:

$ psql -U postgres -d mysandbox -f mycompany.sql