VersionTasks v0.11.2 mix version.bin.db View Source
This command will create helper scripts to manage the backup and restore of your database.
There are two possible arguments
backup_root
— Where to store backupsdbname
— The name of your database
Both arugments are optional and default to
backup_root
— /src/{appname}backupdbname
— {appname}
If your application is called namedb, then running the following
mix version.bin.db
Will create the following scripts
- rel/commands/backup
- rel/commands/restore
The underlying script assumes lots of things, so be sure to test it out and tweak it to your needs (it is meant as a scaffold for you to customize). If there are any generic customizations you feel others might like, then please let me know through a Pull-Request against this project.
Here’s what the output of the backup looks like (may differ slightly based on the version you are running),
#!/bin/bash
NOW=${NOW:=$(date +"%Y%m%d%H%M%S")}
VERSION=${VERSION:=$(mix version.current)}
DBNAME=namedb
BACKUP_ROOT=/src/namedbbackup
FNAME=${DBNAME}_${VERSION}_${NOW}
(cd ${BACKUP_ROOT} && \
pg_dump --create --clean ${DBNAME} > ${FNAME}.sql && \
tar zcf ${FNAME}.tar.gz ${FNAME}.sql && \
ln -sf ${FNAME}.tar.gz ${DBNAME}_${VERSION}.tar.gz && \
ln -sf ${FNAME}.tar.gz ${DBNAME}.tar.gz && \
git add . && \
git commit -m "Backup ${DBNAME} v${VERSION} (${NOW})" && \
git push)
If you want these scripts available as part of your distillery release, then
be sure to update your ./rel/config.exs
as follows [edit the namedb
to
that of your actual application].
release :namedb do
...
set commands: [
"backup": "rel/commands/backup",
"restore": "rel/commands/restore"
]
end
Link to this section Summary
Link to this section Functions
A task needs to implement run
which receives
a list of command line args.
Callback implementation for Mix.Task.run/1
.