Summary: | koha-restore: Allow database dump to be restored to another Koha instance | ||
---|---|---|---|
Product: | Koha | Reporter: | Mason James <mtj> |
Component: | Command-line Utilities | Assignee: | Galen Charlton <gmcharlt> |
Status: | NEW --- | QA Contact: | Testopia <testopia> |
Severity: | enhancement | ||
Priority: | P5 - low | CC: | m.de.rooy, robin, rudolfbyker |
Version: | Main | ||
Hardware: | All | ||
OS: | All | ||
See Also: | https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=23346 | ||
Change sponsored?: | --- | Patch complexity: | --- |
Documentation contact: | Documentation submission: | ||
Text to go in the release notes: | Version(s) released in: | ||
Circulation function: | |||
Bug Depends on: | |||
Bug Blocks: | 35502 |
Description
Mason James
2016-01-26 04:31:46 UTC
Problem is the hardcoded database name in the sql dump coming from the --databases parameter of mysqldump. We could make this an option ? (In reply to Marcel de Rooy from comment #2) > Problem is the hardcoded database name in the sql dump coming from the > --databases parameter of mysqldump. > We could make this an option ? And it would need passing the instance name to mysql in koha-restore. diff without.sql with.sql 18a19,26 > -- Current Database: `koha_master` > -- > > CREATE DATABASE /*!32312 IF NOT EXISTS*/ `koha_master` /*!40100 DEFAULT CHARACTER SET utf8mb4 */; > > USE `koha_master`; > > -- 6743c6751 < -- Dump completed on 2019-07-19 10:20:42 --- > -- Dump completed on 2019-07-19 10:16:49 Another option is to use sed to replace the USE and CREATE DATABASE commands using regular expressions. This can be done using pipes, without creating a new dump. I wrote this bash function a while ago, which imports a gzipped Koha sql-dump. The first argument is the name of the database you want to create, and the second argument is the file name to import from. function import_db { DB="$1" F="$2" # Change the database names when importing. REPLACE1="s/^CREATE DATABASE.*/CREATE DATABASE ${DB};/" REPLACE2='s/USE `koha_rsc`;/USE `'"${DB}"'`;/' # Can't import if it exists, so drop it. drop_db "$DB" echo "Importing database $DB from $F …" zcat "${F}" | sed "${REPLACE1}; ${REPLACE2}" | mysql -u "$MYSQL_USER" -p"$MYSQL_PASS" } Sorry, you also need this function: function drop_db { DB="$1" echo "Dropping $DB …" mysql -u "$MYSQL_USER" -p"$MYSQL_PASS" -e "DROP DATABASE IF EXISTS $DB;" } (In reply to Rudolf Byker from comment #6) > Another option is to use sed to replace the USE and CREATE DATABASE commands > using regular expressions. This can be done using pipes, without creating a > new dump. I wrote this bash function a while ago, which imports a gzipped > Koha sql-dump. The first argument is the name of the database you want to > create, and the second argument is the file name to import from. Thx for sharing. Personally I would opt for creating a dump without db-name instead of search/replace. With a bad databasename you will be in trouble.. But sure, it can be done. |