Merge lp:~mwhudson/lava-deployment-tool/split-restore-command into lp:~linaro-validation/lava-deployment-tool/trunk

Proposed by Michael Hudson-Doyle
Status: Merged
Merged at revision: 183
Proposed branch: lp:~mwhudson/lava-deployment-tool/split-restore-command
Merge into: lp:~linaro-validation/lava-deployment-tool/trunk
Diff against target: 136 lines (+65/-26)
1 file modified
lava-deployment-tool (+65/-26)
To merge this branch: bzr merge lp:~mwhudson/lava-deployment-tool/split-restore-command
Reviewer Review Type Date Requested Status
Zygmunt Krynicki (community) Approve
Review via email: mp+104481@code.launchpad.net

Description of the change

Hi,

This branch splits out a restore-db command from the restore command, as sometimes I find I only really care about the db, not the (enormous) media files.

I intend to set up staging to run this regularly -- perhaps every weekend.

Cheers,
mwh

To post a comment you must log in.
Revision history for this message
Zygmunt Krynicki (zyga) wrote :

+1

No issues that I can see

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lava-deployment-tool'
2--- lava-deployment-tool 2012-04-25 08:02:22 +0000
3+++ lava-deployment-tool 2012-05-03 01:27:18 +0000
4@@ -1551,7 +1551,7 @@
5 }
6
7
8-cmd_restore() {
9+_find_snapshot () {
10 LAVA_INSTANCE=${1}
11
12 check_min_version
13@@ -1568,32 +1568,19 @@
14 local SNAPSHOT_PATH_ALT="$LAVA_ROOT/backups/$SNAPSHOT_ID"
15
16 if [ -e "$SNAPSHOT_PATH" ]; then
17- SNAPSHOT="$SNAPSHOT_PATH"
18+ echo "$SNAPSHOT_PATH"
19 else
20 if [ -e "$SNAPSHOT_PATH_ALT" ]; then
21- SNAPSHOT="$SNAPSHOT_PATH_ALT"
22+ echo "$SNAPSHOT_PATH_ALT"
23 else
24 echo "Cannot find snapshot called '$SNAPSHOT_ID'"
25 echo "It should be in $SNAPSHOT_PATH or $SNAPSHOT_PATH_ALT (alternative)"
26- return
27+ exit 1
28 fi
29 fi
30-
31- _load_configuration "$LAVA_INSTANCE"
32-
33- db_snapshot="$SNAPSHOT/database.dump"
34- files_snapshot="$SNAPSHOT/files.tar.gz"
35-
36- if [ \! -f "$db_snapshot" -o \! -f "$files_snapshot" ]; then
37- echo "$SNAPSHOT does not look like a complete snapshot"
38- return
39- fi
40-
41- echo "Are you sure you want to restore instance $LAVA_INSTANCE from"
42- echo "$SNAPSHOT_ID? This will DESTROY the existing state of $LAVA_INSTANCE"
43- echo
44- read -p "Type RESTORE to continue: " RESPONSE
45- test "$RESPONSE" = 'RESTORE' || return
46+}
47+
48+_restore_db_from_dump () {
49
50 # Load database configuration
51 . $LAVA_PREFIX/$LAVA_INSTANCE/etc/lava-server/default_database.conf
52@@ -1611,9 +1598,6 @@
53
54 set -x
55
56- # Stop the instance
57- sudo stop lava-instance LAVA_INSTANCE=$LAVA_INSTANCE || true
58-
59 sudo -u postgres dropdb \
60 --port $dbport \
61 $dbname || true
62@@ -1628,7 +1612,62 @@
63 --port $dbport \
64 --role $dbuser \
65 --dbname $dbname \
66- $SNAPSHOT/database.dump > /dev/null
67+ "${1}" > /dev/null
68+}
69+
70+cmd_restore-db () {
71+ LAVA_INSTANCE=${1}
72+ local SNAPSHOT_ID=${2}
73+ SNAPSHOT="$(_find_snapshot $LAVA_INSTANCE $SNAPSHOT_ID)"
74+
75+ _load_configuration "$LAVA_INSTANCE"
76+
77+ db_snapshot="$SNAPSHOT/database.dump"
78+
79+ if [ \! -f "$db_snapshot" ]; then
80+ echo "$SNAPSHOT does not contain a db snapshot"
81+ exit 1
82+ fi
83+
84+ echo "Are you sure you want to restore the database of $LAVA_INSTANCE from"
85+ echo "$SNAPSHOT_ID? This will DESTROY the existing database of $LAVA_INSTANCE"
86+ echo
87+ read -p "Type RESTORE to continue: " RESPONSE
88+ test "$RESPONSE" = 'RESTORE' || return
89+
90+ # Stop the instance
91+ sudo stop lava-instance LAVA_INSTANCE=$LAVA_INSTANCE || true
92+
93+ _restore_db_from_dump "$db_snapshot"
94+
95+ sudo start lava-instance LAVA_INSTANCE=$LAVA_INSTANCE
96+
97+ echo "Done"
98+
99+}
100+
101+cmd_restore() {
102+ LAVA_INSTANCE=${1}
103+ local SNAPSHOT_ID=${2}
104+ SNAPSHOT="$(_find_snapshot $LAVA_INSTANCE $SNAPSHOT_ID)"
105+
106+ _load_configuration "$LAVA_INSTANCE"
107+
108+ db_snapshot="$SNAPSHOT/database.dump"
109+ files_snapshot="$SNAPSHOT/files.tar.gz"
110+
111+ if [ \! -f "$db_snapshot" -o \! -f "$files_snapshot" ]; then
112+ echo "$SNAPSHOT does not look like a complete snapshot"
113+ return
114+ fi
115+
116+ echo "Are you sure you want to restore instance $LAVA_INSTANCE from"
117+ echo "$SNAPSHOT_ID? This will DESTROY the existing state of $LAVA_INSTANCE"
118+ echo
119+ read -p "Type RESTORE to continue: " RESPONSE
120+ test "$RESPONSE" = 'RESTORE' || return
121+
122+ _restore_db_from_dump "$db_snapshot"
123
124 sudo rm -rf $LAVA_PREFIX/$LAVA_INSTANCE/var/lib/lava-server/
125 mkdir -p $LAVA_PREFIX/$LAVA_INSTANCE/var/lib/lava-server/
126@@ -1997,8 +2036,8 @@
127 backup)
128 cmd_backup "$@"
129 ;;
130- restore)
131- cmd_restore "$@"
132+ restore-*)
133+ cmd_$cmd "$@"
134 ;;
135 install_*)
136 set -x

Subscribers

People subscribed via source and target branches