Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openbis
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sispub
openbis
Commits
a1145184
Commit
a1145184
authored
13 years ago
by
felmer
Browse files
Options
Downloads
Patches
Plain Diff
LMS-2471 improved create-snapshot.sh, counterpart restore-from-snapshot.sh added
SVN: 22584
parent
778aa3d8
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
openbis_all/source/bash/create-snapshot.sh
+39
-26
39 additions, 26 deletions
openbis_all/source/bash/create-snapshot.sh
openbis_all/source/bash/restore-from-snapshot.sh
+90
-0
90 additions, 0 deletions
openbis_all/source/bash/restore-from-snapshot.sh
with
129 additions
and
26 deletions
openbis_all/source/bash/create-snapshot.sh
+
39
−
26
View file @
a1145184
...
...
@@ -4,7 +4,7 @@
#
# usage: create-snapshot.sh <configuration file>
#
# The configuration file
s knows
the following key-value pairs (stored as <key> = <value>):
# The configuration file
has to have
the following key-value pairs (stored as <key> = <value>):
#
# repository Path to the directory which will store the snapshot.
# servers Path to to a directory which contains the folders 'datastore_server'
...
...
@@ -14,7 +14,6 @@
# databases Space separated list of database to be dumped.
# index Relative path to the lucene index.
# It is relative to <servers path>/openBIS-server/jetty/.
# If this optional attribute is missing no lucene index will added to the snapshot.
#
# Important Notes:
# - This script should be run after all servers have been stopped.
...
...
@@ -31,6 +30,10 @@ if [ $# -ne 1 ]; then
exit
1
fi
##################################################
#
# Gathering parameters
#
CONFIGURATION_FILE
=
"
$1
"
SERVERS_PATH
=
`
getValue
$CONFIGURATION_FILE
servers
`
...
...
@@ -64,30 +67,42 @@ if [ -z "$DATABASES" ]; then
echo
"At least one database has to be specified in
$CONFIGURATION_FILE
."
exit
1
fi
INDEX
=
`
getValue
$CONFIGURATION_FILE
index
`
if
[
-n
"
$INDEX
"
]
;
then
if
[
!
-d
"
$INDEX
"
]
;
then
mkdir
-p
"
$INDEX
"
fi
INDEX
=
"
$OPENBIS_AS_ROOT
"
`
getValue
$CONFIGURATION_FILE
index
`
if
[
-z
"
$INDEX
"
]
;
then
echo
"Index not specified in
$CONFIGURATION_FILE
."
fi
mkdir
-p
"
$INDEX
"
TIMESTAMP
=
`
date
+%Y-%m-%d_%H:%M:%S
`
SNAPSHOT_FOLDER
=
"openbis-snapshot-
$TIMESTAMP
"
SNAPSHOT
=
"
$REPOSITORY
/
$SNAPSHOT_FOLDER
"
SNAPSHOT_FOLDER
_NAME
=
"openbis-snapshot-
$TIMESTAMP
"
SNAPSHOT
=
"
$REPOSITORY
/
$SNAPSHOT_FOLDER
_NAME
"
##################################################
#
#
Star
ting snapshot
creation
#
Crea
ting snapshot
#
echo
"====
c
reating snapshot
$SNAPSHOT
.tgz"
echo
"====
C
reating snapshot
$SNAPSHOT
.tgz"
mkdir
"
$SNAPSHOT
"
cp
-p
"
$CONFIGURATION_FILE
"
"
$SNAPSHOT
"
cp
-p
"
$CONFIGURATION_FILE
"
"
$SNAPSHOT
/snapshot.config
"
############## dump the store ##############
tar
-cf
"
$SNAPSHOT
/store.tar"
-C
"
$STORE
"
.
if
[
$?
-ne
0
]
;
then
echo
"Error creating store dump. Snapshot creation aborted."
exit
1
fi
for
path
in
"
$STORE
"
/
*
;
do
index_of_last_slash
=
`
expr
$path
:
'.*/'
`
file_name
=
${
path
:
$index_of_last_slash
}
if
[
`
expr
$file_name
:
'[0-9]*'
`
-ne
0
]
;
then
if
[
-h
"
$path
"
]
;
then
echo
"Share
$file_name
is not dumped because it is a symbolic link."
else
echo
"Start dumping share
$file_name
."
parent_folder
=
${
path
:0:
$index_of_last_slash
}
tar
-rf
"
$SNAPSHOT
/store.tar"
-C
"
$parent_folder
"
$file_name
if
[
$?
-ne
0
]
;
then
echo
"Error while dumping share
$file_name
. Snapshot creation aborted."
exit
1
fi
echo
"Share
$file_name
sucessfully dumped."
fi
fi
done
echo
"Dump of store
$STORE
has been successfully created."
############## dump databases ##############
for
db
in
$DATABASES
;
do
...
...
@@ -98,17 +113,15 @@ for db in $DATABASES; do
fi
echo
"Database '
$db
' has been successfully dumped."
done
############## dump index (if requested) ##############
if
[
-n
"
$INDEX
"
]
;
then
tar
-cf
"
$SNAPSHOT
/index.tar"
-C
"
$INDEX
"
.
if
[
$?
-ne
0
]
;
then
echo
"Error creating index dump. Snapshot creation aborted."
exit
1
fi
echo
"Dump of index
$INDEX
has been successfully created."
############## dump index ##############
tar
-cf
"
$SNAPSHOT
/index.tar"
-C
"
$INDEX
"
.
if
[
$?
-ne
0
]
;
then
echo
"Error creating index dump. Snapshot creation aborted."
exit
1
fi
echo
"Dump of index
$INDEX
has been successfully created."
############## packaging ##############
tar
-zcf
"
$SNAPSHOT
.tgz"
-C
"
$REPOSITORY
"
"
$SNAPSHOT_FOLDER
"
tar
-zcf
"
$SNAPSHOT
.tgz"
-C
"
$REPOSITORY
"
"
$SNAPSHOT_FOLDER
_NAME
"
if
[
$?
-ne
0
]
;
then
echo
"Error packaging snapshot
$SNAPSHOT
."
exit
1
...
...
This diff is collapsed.
Click to expand it.
openbis_all/source/bash/restore-from-snapshot.sh
0 → 100755
+
90
−
0
View file @
a1145184
#! /bin/bash
#
# Restores store, databases and optionally lucene index of an openBIS instance from a snapshot
# created by create-snapshot.sh.
#
# usage: restore-from-snapshot.sh <snapshot file>
#
function
getValue
{
file
=
$1
key
=
$2
awk
-F
' *= *'
-v
key
=
$2
'{map[$1] = $2} END {print map[key]}'
$file
}
function
cleanUpAndExit
{
rm
-rf
$TMPDIR
exit
1
}
if
[
$#
-ne
1
]
;
then
echo
"Usage: restore-from-snapshot.sh <snapshot file>"
exit
1
fi
##################################################
#
# Gathering parameters
#
SNAPSHOT_FILE
=
$1
USER
=
$(
whoami
)
TMPDIR
=
`
mktemp
-d
/tmp/snapshot-XXXXX
`
echo
"temp folder:
$TMPDIR
"
tar
-zxf
$SNAPSHOT_FILE
-C
$TMPDIR
if
[
$?
-ne
0
]
;
then
echo
"Error: Couldn't unzip and untar
$SNAPSHOT_FILE
."
cleanUpAndExit
fi
for
f
in
$TMPDIR
/
*
;
do
SNAPSHOT_FILES
=
"
$f
"
;
done
SNAPSHOT_CONFIG_FILE
=
$SNAPSHOT_FILES
/snapshot.config
SERVERS_PATH
=
`
getValue
$SNAPSHOT_CONFIG_FILE
servers
`
OPENBIS_AS_ROOT
=
"
$SERVERS_PATH
/openBIS-server/jetty/"
if
[
!
-d
"
$OPENBIS_AS_ROOT
"
]
;
then
echo
"Error:
$OPENBIS_AS_ROOT
isn't a directory."
echo
"Most probable reason:
$SERVERS_PATH
doesn't point to a valid openBIS instance."
cleanUpAndExit
fi
STORE
=
`
getValue
$SNAPSHOT_CONFIG_FILE
store
`
DATABASES
=
`
getValue
$SNAPSHOT_CONFIG_FILE
databases
`
INDEX
=
"
$OPENBIS_AS_ROOT
"
`
getValue
$SNAPSHOT_CONFIG_FILE
index
`
##################################################
#
# Restoring from snapshot
#
echo
"==== Restore from
$SNAPSHOT_FILE
"
############## restore store ##############
echo
"Starting to restore the store
$STORE
."
rm
-rf
"
$STORE
"
mkdir
-p
"
$STORE
"
tar
-xf
$SNAPSHOT_FILES
/store.tar
-C
"
$STORE
"
if
[
$?
-ne
0
]
;
then
echo
"Error: Couldn't restore store. Restoring aborted."
cleanUpAndExit
fi
echo
"Store successfully restored."
############## restore databases ##############
for
db
in
$DATABASES
;
do
psql
-U
postgres
-q
-c
"drop database
$db
"
psql
-U
postgres
-q
-c
"create database
$db
with owner
$USER
"
psql
-U
$USER
-q
-d
$db
-f
$SNAPSHOT_FILES
/
$db
.sql
>
/dev/null
if
[
$?
-ne
0
]
;
then
echo
"Error: Couldn't restore database '
$db
'."
cleanUpAndExit
fi
echo
"Database '
$db
' has been successfully restored."
done
############## restore store ##############
if
[
-n
"
$INDEX
"
]
;
then
tar
-xf
$SNAPSHOT_FILES
/index.tar
-C
"
$INDEX
"
if
[
$?
-ne
0
]
;
then
echo
"Error: Couldn't restore index."
cleanUpAndExit
fi
echo
"Index has been successfully restored."
fi
rm
-rf
$TMPDIR
echo
"==== Successfully restored from
$SNAPSHOT_FILE
"
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment