From e1c3360f04830c56468ca6210361fe794ea3c987 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Thu, 10 Mar 2022 17:16:52 +0530 Subject: Accept connection parameters and dump directory as arguments. * dump.scm: Import (rnrs programs). (%connection-settings): New variable. (call-with-database): Use %connection-settings. (%database-name): Delete variable. (%dump-directory): Set from command-line arguments. (dump-data-table): Use %connection-settings instead of %database-name. * README.org (Using): Add command-line arguments to usage instructions. --- README.org | 10 +++++----- dump.scm | 37 +++++++++++++++++++------------------ 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/README.org b/README.org index fbc5705..b688d3e 100644 --- a/README.org +++ b/README.org @@ -22,15 +22,15 @@ brackets with the appropriate values. (port . )) #+END_SRC -Then, to dump the database, run +Then, to dump the database to ~/data/dump, run #+BEGIN_SRC shell - $ ./pre-inst-env ./dump.scm + $ ./pre-inst-env ./dump.scm conn.scm ~/data/dump #+END_SRC -The database will be dumped to ~/data/dump/. Make sure there is enough -free space! It's best to dump the database on penguin2 where disk -space and bandwidth are not significant constraints. +Make sure there is enough free space! It's best to dump the database +on penguin2 where disk space and bandwidth are not significant +constraints. * Contributing diff --git a/dump.scm b/dump.scm index 112cc1a..30cb8dd 100755 --- a/dump.scm +++ b/dump.scm @@ -1,7 +1,8 @@ #! /usr/bin/env guile !# -(use-modules (rnrs io ports) +(use-modules (rnrs programs) + (rnrs io ports) (srfi srfi-1) (srfi srfi-26) (ice-9 match) @@ -13,25 +14,24 @@ ;;; GeneNetwork database connection parameters and dump path +(define %connection-settings + (call-with-input-file (list-ref (command-line) 0) + read)) + (define (call-with-genenetwork-database proc) - (let ((connection-settings (call-with-input-file "conn.scm" read))) - (call-with-database "mysql" (string-join - (list (assq-ref connection-settings 'username) - (assq-ref connection-settings 'password) - (assq-ref connection-settings 'database) - "tcp" - (assq-ref connection-settings 'host) - (number->string - (assq-ref connection-settings 'port))) - ":") - proc))) - -(define %database-name - (assq-ref (call-with-input-file "conn.scm" read) - 'database)) + (call-with-database "mysql" (string-join + (list (assq-ref %connection-settings 'username) + (assq-ref %connection-settings 'password) + (assq-ref %connection-settings 'database) + "tcp" + (assq-ref %connection-settings 'host) + (number->string + (assq-ref %connection-settings 'port))) + ":") + proc)) (define %dump-directory - (string-append (getenv "HOME") "/data/dump")) + (list-ref (command-line) 1)) (define (call-with-dump-file filename proc) (let ((absolute-path (string-append %dump-directory filename))) @@ -717,7 +717,8 @@ is a object." (select-query ((information_schema.tables table_name) (information_schema.tables data_length)) (information_schema.tables) - (format #f "WHERE table_schema = '~a'" %database-name))))) + (format #f "WHERE table_schema = '~a'" + (assq-ref %connection-settings 'database)))))) (define (dump-schema db) (let ((tables (tables db))) -- cgit v1.2.3