mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-16 18:43:18 +08:00
Writing a shell script correctly can be hard even for a skilled programmer. shellcheck is a static analysis tool that helps catch common errors in shell scripts. We now have 36 executable scripts in our repository, for which shellcheck reports 126 errors (calculated like find . -type f -executable -exec bash -c '[ "$(file --brief --mime-type "$1")" == "text/x-shellscript" ]' sh {} \; -exec shellcheck -f gcc --exclude=SC2086 {} \; | cut -d: -f1 | sort | uniq | wc -l). This commit fixes these warnings and adds a GitHub actions workflow that runs shellcheck on all the executable shell scripts in the repository. The warning SC2086: Double quote to prevent globbing and word splitting is disabled globally, because it has little practical consequences, sometimes leads to false positives, and is general is too widespread because people forget to quote.
47 lines
1.3 KiB
Bash
Executable File
47 lines
1.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# Copyright (c) 2016-2018 Timescale, Inc. All Rights Reserved.
|
|
#
|
|
# This file is licensed under the Apache License, see LICENSE-APACHE
|
|
# at the top level directory of the timescaledb distribution.
|
|
|
|
# This script is used for restoring a hypertable from a tarball made with
|
|
# ts_dump.sh. It unarchives the tarball, producing a schema file and data file,
|
|
# which are then restore separately.
|
|
|
|
|
|
if [[ -z "$1" || -z "$2" ]]; then
|
|
echo "Usage: $0 hypertable tarfile_name"
|
|
echo " hypertable - Hypertable to restore"
|
|
echo " tarfile_name - Name of the tarball created by ts_dump.sh to restore"
|
|
echo " "
|
|
echo "Any connection options for pg_restore/psql (e.g. -d database, -U username) should be listed at the end"
|
|
exit 1
|
|
|
|
fi
|
|
|
|
HYPERTABLE=$1
|
|
TARFILE=$2
|
|
PREFIX="${TARFILE/.tar.gz/}"
|
|
shift 2
|
|
echo "Unarchiving tarball..."
|
|
tar xvzf $TARFILE
|
|
|
|
echo "Restoring hypertable's schema..."
|
|
if ! psql -q -v "ON_ERROR_STOP=1" "$@" < $PREFIX-schema.sql
|
|
then
|
|
echo "Restoring schema failed, exiting."
|
|
rm $PREFIX-data.csv
|
|
rm $PREFIX-schema.sql
|
|
exit $?
|
|
fi
|
|
|
|
echo "Restoring hypertable's data..."
|
|
if ! psql "$@" -v "ON_ERROR_STOP=1" -c "\COPY $HYPERTABLE FROM $PREFIX-data.csv DELIMITER ',' CSV"
|
|
then
|
|
echo "Restoring data failed, exiting."
|
|
fi
|
|
|
|
rm $PREFIX-data.csv
|
|
rm $PREFIX-schema.sql
|