From e0f021cc1c8a6e432c8ad2a7b4e2be393224d9a6 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Wed, 23 Jan 2013 17:07:31 +0100 Subject: [PATCH] dumps all package data --- hsarjcli/scripting/package_dump.js | 50 +++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/hsarjcli/scripting/package_dump.js b/hsarjcli/scripting/package_dump.js index 32e1bbd..cccd11e 100644 --- a/hsarjcli/scripting/package_dump.js +++ b/hsarjcli/scripting/package_dump.js @@ -1,6 +1,48 @@ var pacs = pac.search(); -var hive = 'h91'; +var hive = 'h99'; var password = 'p!' + (new String(Math.random())).substring(2,16) + '!'; +function runbash(cmd) { + var runtime = java.lang.Runtime.getRuntime(); + runtime.exec(["bash", "-c", cmd]); +} +function mysqldump(pac, db) { + var dump = "/home/pacs/" + pac + "/.bak/mysql-" + db + ".dmp.gz"; + var cmd = "mysqldump --create-options --flush-logs --force --quote-names --quick --single-transaction " + + db + "|gzip --best|secat --user=" + pac + " --group=" + pac + " --umask=007 --output=" + dump; + runbash(cmd); +} +function pgsqldump(pac, db) { + var dump = "/home/pacs/" + pac + "/.bak/pgsql-" + db + ".dmp.gz"; + var cmd = "export PGUSER=postgres; pg_dump --disable-triggers --oids --compress=0 --format=c " + + db + "|gzip --best|secat --user=" + pac + " --group=" + pac + " --umask=007 --output=" + dump; + runbash(cmd); +} +function crontabdump(pac, user) { + var dump = "/home/pacs/" + pac + "/.bak/crontab-" + user + ".gz"; + var cmd = "crontab -u " + user + " -l" + + "|gzip --best|secat --user=" + pac + " --group=" + pac + " --umask=007 --output=" + dump; + runbash(cmd); +} +function shadowdump(pac) { + var dump = "/home/pacs/" + pac + "/.bak/shadow.gz"; + var cmd = "grep -e '^" + pac + "' /etc/shadow|cut -f1-2 -d':' " + + "|gzip --best|secat --user=" + pac + " --group=" + pac + " --umask=007 --output=" + dump; + runbash(cmd); +} +function mysqlpasswddump(pac) { + var dump = "/home/pacs/" + pac + "/.bak/mysql_passwd.gz"; + var sql = "select concat('update user set Password=\\\'', Password, '\\\' where User=\\\'', User, '\\\';')" + + " as update_passwd from user where user like '" + pac + "%';"; + var cmd = "( ( echo \"" + sql + "\"|mysql mysql ) ; echo \"flush privileges;\" )" + + "|sed '1d'|gzip --best|secat --user=" + pac + " --group=" + pac + " --umask=007 --output=" + dump; + runbash(cmd); +} +function pgsqlpasswddump(pac) { + var dump = "/home/pacs/" + pac + "/.bak/pgsql_passwd.gz"; + var cmd = "export PGUSER=postgres; pg_dumpall -r | grep ^ALTER | grep " + pac + + "|gzip --best|secat --user=" + pac + " --group=" + pac + " --umask=007 --output=" + dump; + runbash(cmd); +} if (pacs.length == 1 && hive != 'undef') { var pacname = pacs[0]['name']; var file = new java.io.FileWriter(pacname + '_dump.js'); @@ -36,6 +78,7 @@ if (pacs.length == 1 && hive != 'undef') { file.write('password: "' + password + '"\n'); file.write('}});\n'); } + crontabdump(pacname, unixusers[idx]['name']); } // Domain var domains = domain.search(); @@ -151,6 +194,7 @@ if (pacs.length == 1 && hive != 'undef') { file.write('owner: "' + pgdbold[idx]['owner'] + '",\n'); file.write('encoding: "' + pgdbold[idx]['encoding'] + '"\n'); file.write('}});\n'); + pgsqldump(pacname, pgdbold[idx]['name']); } // MySQL var myuserold = mysqluser.search(); @@ -167,8 +211,12 @@ if (pacs.length == 1 && hive != 'undef') { file.write('owner: "' + mydbold[idx]['owner'] + '",\n'); file.write('encoding: "' + mydbold[idx]['encoding'] + '"\n'); file.write('}});\n'); + mysqldump(pacname, mydbold[idx]['name']); } file.close(); + shadowdump(pacname); + mysqlpasswddump(pacname); + pgsqlpasswddump(pacname); } else { print('run as pac-owner!\n'); } \ No newline at end of file