functions 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. #!/usr/bin/env bash
  2. #
  3. # Zammad backup script functions
  4. #
  5. function demand_backup_conf () {
  6. if [ -f "${BACKUP_SCRIPT_PATH}/config" ]; then
  7. # Ensure we're inside of our Backup-Script folder (see issue 2508)
  8. # shellcheck disable=SC2164
  9. cd "${BACKUP_SCRIPT_PATH}"
  10. # import config
  11. . ${BACKUP_SCRIPT_PATH}/config
  12. else
  13. echo -e "\n The 'config' file is missing!"
  14. echo -e " Please copy ${BACKUP_SCRIPT_PATH}/config.dist to ${BACKUP_SCRIPT_PATH}/config before running $0!\n"
  15. echo -e " Learn more about the backup configuration at https://docs.zammad.org/en/latest/appendix/backup-and-restore/configuration.html"
  16. exit 1
  17. fi
  18. # Check if filesystem full dump setting exists and fall back if not
  19. if [ -z ${FULL_FS_DUMP+x} ]; then
  20. # Falling back to old default behavior
  21. FULL_FS_DUMP='yes'
  22. if [ "${DEBUG}" == "yes" ]; then
  23. echo "FULL_FS_DUMP is not set, falling back to 'yes' to produce a full backup."
  24. fi
  25. fi
  26. }
  27. function get_zammad_dir () {
  28. ZAMMAD_DIR="$(echo ${BACKUP_SCRIPT_PATH} | sed -e 's#/contrib/backup.*##g')"
  29. }
  30. function get_backup_date () {
  31. TIMESTAMP="$(date +'%Y%m%d%H%M%S')"
  32. if [ "${DEBUG}" == "yes" ]; then
  33. echo "timestamp is ${TIMESTAMP}"
  34. fi
  35. }
  36. function delete_old_backups () {
  37. # Use -mmin to clean up files as -mtime (days) is too unprecise.
  38. # However, add +60 minutes to allow for the backup script run time, so that
  39. # backups created a few minutes more than a day ago are not already purged.
  40. FILES_TO_DELETE=$(test -d ${BACKUP_DIR} && find ${BACKUP_DIR}/*_zammad_*.gz -type f -mmin +$(((60*24)*${HOLD_DAYS}+60)))
  41. if [[ -n ${FILES_TO_DELETE} ]]; then
  42. if [ "${DEBUG}" == "yes" ]; then
  43. echo "Deleting old backups according to value set in HOLD_DAYS."
  44. fi
  45. echo "${FILES_TO_DELETE}" | xargs rm
  46. else
  47. if [ "${DEBUG}" == "yes" ]; then
  48. echo "No files found matching value set in HOLD_DAYS. No files deleted."
  49. fi
  50. fi
  51. }
  52. function get_db_credentials () {
  53. DB_ADAPTER="$(grep -m 1 '^[[:space:]]*adapter:' < ${ZAMMAD_DIR}/config/database.yml | sed -e 's/.*adapter:[[:space:]]*//g')"
  54. DB_HOST="$(grep -m 1 '^[[:space:]]*host:' < ${ZAMMAD_DIR}/config/database.yml | sed -e 's/.*host:[[:space:]]*//g')"
  55. DB_PORT="$(grep -m 1 '^[[:space:]]*port:' < ${ZAMMAD_DIR}/config/database.yml | sed -e 's/.*port:[[:space:]]*//g')"
  56. DB_NAME="$(grep -m 1 '^[[:space:]]*database:' < ${ZAMMAD_DIR}/config/database.yml | sed -e 's/.*database:[[:space:]]* //g')"
  57. DB_USER="$(grep -m 1 '^[[:space:]]*username:' < ${ZAMMAD_DIR}/config/database.yml | sed -e 's/.*username:[[:space:]]*//g')"
  58. DB_PASS="$(grep -m 1 '^[[:space:]]*password:' < ${ZAMMAD_DIR}/config/database.yml | sed -e 's/.*password:[[:space:]]*//g')"
  59. if [ "${DB_ADAPTER}" == "postgresql" ]; then
  60. # Ensure that HOST and PORT are not empty, provide defaults if needed.
  61. if [ "${DB_HOST}x" == "x" ]; then
  62. DB_HOST="localhost"
  63. fi
  64. if [ "${DB_PORT}x" == "x" ]; then
  65. DB_PORT="5432"
  66. fi
  67. fi
  68. if [ "${DEBUG}" == "yes" ]; then
  69. echo "adapter=${DB_ADAPTER} dbhost=${DB_HOST} dbport=${DB_PORT} dbname=${DB_NAME} dbuser=${DB_USER} dbpass=${DB_PASS}"
  70. fi
  71. }
  72. function backup_dir_create () {
  73. test -d ${BACKUP_DIR} || mkdir -p ${BACKUP_DIR}
  74. state=$?
  75. if [ "${state}" == "1" ]; then
  76. echo -e "\n\n # ERROR(${state}) - Creation of backup directory failed. Please double check permissions."
  77. echo -e " #-> BACKUP WAS NOT SUCCESSFUL"
  78. exit 3
  79. fi
  80. if [ "${DEBUG}" == "yes" ]; then
  81. echo "backup dir is ${BACKUP_DIR}"
  82. fi
  83. }
  84. backup_file_write_test () {
  85. # We're testing if we can actually write into the provided directory with
  86. # the current user before continuing.
  87. touch ${BACKUP_DIR}/write_test 2> /dev/null
  88. state=$?
  89. if [ "${state}" == "1" ]; then
  90. # We're checking for critical restoration errors
  91. # It may not cover all possible errors which is out of scope of this script
  92. echo -e "\n\n # ERROR(${state}) - Creation of backup files was not possible. Double check permissions."
  93. echo -e " #-> BACKUP WAS NOT SUCCESSFUL"
  94. exit 3
  95. fi
  96. rm -f ${BACKUP_DIR}/write_test
  97. }
  98. backup_file_read_test () {
  99. # We're testing if we can read the provided file names before
  100. # starting. Other wise handling would be more difficult depending on
  101. # the installation type
  102. if [ "${DEBUG}" == "yes" ]; then
  103. echo "I've been looking for these backup files: "
  104. echo "- ${BACKUP_DIR}/${RESTORE_FILE_DATE}_zammad_files.tar.gz"
  105. echo "- ${BACKUP_DIR}/${RESTORE_DB_DATE}_zammad_db.${DB_FILE_EXT}.gz"
  106. fi
  107. if [[ (! -r "${BACKUP_DIR}/${RESTORE_FILE_DATE}_zammad_files.tar.gz") || (! -r "${BACKUP_DIR}/${RESTORE_DB_DATE}_zammad_db.${DB_FILE_EXT}.gz") ]]; then
  108. echo -e "\n\n # ERROR - Cannot read on or more of my backup files. Double check permissions."
  109. echo -e " #-> RESTORE WAS NOT SUCCESSFUL"
  110. exit 3
  111. fi
  112. }
  113. function check_empty_password () {
  114. if [ "${DB_PASS}x" == "x" ]; then
  115. echo "# ERROR - Found an empty database password ..."
  116. echo "# - This may be intended or not, however - this script does not support this."
  117. echo "# - If you don't know how to continue, consult https://docs.zammad.org/en/latest/appendix/backup-and-restore/index.html"
  118. exit 2
  119. fi
  120. }
  121. function backup_files () {
  122. echo "creating file backup..."
  123. if [ "${FULL_FS_DUMP}" == 'yes' ]; then
  124. echo " ... as full dump"
  125. tar -C / -czf ${BACKUP_DIR}/${TIMESTAMP}_zammad_files.tar.gz\
  126. --exclude='tmp' --exclude 'node_modules' --exclude '.git' --exclude '.yarn/cache' --exclude='config/database.yml' ${ZAMMAD_DIR#/}
  127. state=$?
  128. else
  129. echo " ... only with productive data (attachments)"
  130. if [ ! -d "${ZAMMAD_DIR}/storage/" ]; then
  131. # Admin has requested an attachment backup only, however, there is no storage
  132. # directory. We'll warn Mr.Admin and create the directory as workaround.
  133. echo " ... WARNING: You don't seem to have any attachments in the file system!"
  134. echo " ... Please consult https://docs.zammad.org/en/latest/appendix/backup-and-restore/troubleshooting.html"
  135. echo " ... Creating empty storage directory so the backup can continue ..."
  136. mkdir -p ${ZAMMAD_DIR}/storage/
  137. chown -R zammad:zammad ${ZAMMAD_DIR}/storage/
  138. fi
  139. if [ -h ${ZAMMAD_DIR}/storage ]; then
  140. echo "... Found symlink, will store both Symlink and Symlink target ..."
  141. REALDIR=$(realpath ${ZAMMAD_DIR}/storage/)
  142. ZAMMAD_STORAGE_DIR="${ZAMMAD_DIR#/}/storage ${REALDIR#/}"
  143. else
  144. ZAMMAD_STORAGE_DIR="${ZAMMAD_DIR#/}/storage/"
  145. fi
  146. tar -C / -czf ${BACKUP_DIR}/${TIMESTAMP}_zammad_files.tar.gz ${ZAMMAD_STORAGE_DIR}
  147. state=$?
  148. fi
  149. if [ $state == '2' ]; then
  150. echo "# ERROR(2) - File backup reported a fatal error."
  151. echo "- Check file permissions and try again."
  152. echo -e " \n# BACKUP WAS NOT SUCCESSFUL"
  153. exit 1
  154. fi
  155. if [ $state == '1' ]; then
  156. echo "# WARNING - Files have changed during backup."
  157. echo "- This indicates your Zammad instance is running and thus may be normal."
  158. fi
  159. ln -sfn ${BACKUP_DIR}/${TIMESTAMP}_zammad_files.tar.gz ${BACKUP_DIR}/latest_zammad_files.tar.gz
  160. }
  161. function create_pgpassfile() {
  162. PGPASSFILE=$(mktemp)
  163. export PGPASSFILE
  164. chmod 600 "$PGPASSFILE"
  165. cat <<EOT > "$PGPASSFILE"
  166. *:*:${DB_NAME}:${DB_USER}:${DB_PASS}
  167. EOT
  168. trap 'rm "$PGPASSFILE"' EXIT
  169. }
  170. function backup_db () {
  171. if [ "${DB_ADAPTER}" == "mysql2" ]; then
  172. echo "creating mysql backup..."
  173. mysqldump --opt --single-transaction ${DB_HOST:+--host $DB_HOST} -u${DB_USER} -p${DB_PASS} ${DB_NAME} | gzip > ${BACKUP_DIR}/${TIMESTAMP}_zammad_db.mysql.gz
  174. ln -sfn ${BACKUP_DIR}/${TIMESTAMP}_zammad_db.mysql.gz ${BACKUP_DIR}/latest_zammad_db.mysql.gz
  175. elif [ "${DB_ADAPTER}" == "postgresql" ]; then
  176. echo "creating postgresql backup..."
  177. create_pgpassfile
  178. pg_dump --dbname "${DB_NAME}" \
  179. --username "${DB_USER}" \
  180. ${DB_HOST:+--host $DB_HOST} \
  181. ${DB_PORT:+--port $DB_PORT} \
  182. --no-privileges --no-owner \
  183. --compress 6 --file "${BACKUP_DIR}/${TIMESTAMP}_zammad_db.psql.gz"
  184. state=$?
  185. if [ "${state}" == "1" ]; then
  186. # We're checking for critical restoration errors
  187. # It may not cover all possible errors which is out of scope of this script
  188. echo -e "\n\n # ERROR(${state}) - Database credentials are wrong or database server configuration is invalid."
  189. echo -e " #-> BACKUP WAS NOT SUCCESSFUL"
  190. exit 2
  191. fi
  192. ln -sfn ${BACKUP_DIR}/${TIMESTAMP}_zammad_db.psql.gz ${BACKUP_DIR}/latest_zammad_db.psql.gz
  193. else
  194. echo -e "\n\n # ERROR - Database type or database.yml incorrect. Unsupported database type found."
  195. echo -e " #-> BACKUP WAS NOT SUCCESSFUL"
  196. exit 2
  197. fi
  198. }
  199. function backup_chmod_dump_data () {
  200. echo "Ensuring dump permissions ..."
  201. chmod 600 ${BACKUP_DIR}/${TIMESTAMP}_zammad_db.*.gz ${BACKUP_DIR}/${TIMESTAMP}_zammad_files.tar.gz
  202. }
  203. function check_database_config_exists () {
  204. if [ -f ${ZAMMAD_DIR}/config/database.yml ]; then
  205. get_db_credentials
  206. else
  207. echo -e "${ZAMMAD_DIR}/config/database.yml is missing. is Zammad configured yet? \nAborting..."
  208. exit 1
  209. fi
  210. }
  211. function restore_warning () {
  212. if [ -n "${1}" ]; then
  213. CHOOSE_RESTORE="yes"
  214. else
  215. echo -e "The restore will delete your current database! \nBe sure to have a backup available! \n"
  216. echo -e "Please ensure to have twice the storage of the uncompressed backup size! \n\n"
  217. echo -e "Note that the restoration USUALLY requires root permissions as services are stopped! \n\n"
  218. echo -e "Enter 'yes' if you want to proceed!"
  219. read -p 'Restore?: ' CHOOSE_RESTORE
  220. fi
  221. if [ "${CHOOSE_RESTORE}" != "yes" ]; then
  222. echo "Restore aborted!"
  223. exit 1
  224. fi
  225. }
  226. function db_helper_warning () {
  227. echo -e " # WARNING: THIS SCRIPT CHANGES CREDENTIALS, DO NOT CONTINUE IF YOU DON'T KNOW WHAT YOU'RE DOING! \n\n"
  228. echo -e " Limitations:"
  229. echo -e " - only works for local postgresql installations"
  230. echo -e " - only works for postgresql\n"
  231. echo -e "Enter 'yes' if you want to proceed!"
  232. read -p 'ALTER zammad users password?: ' DB_HELPER
  233. if [ "${DB_HELPER}" != "yes" ]; then
  234. echo "Helper script aborted!"
  235. exit 1
  236. fi
  237. }
  238. function get_restore_dates () {
  239. RESTORE_FILE_DATES="$(find ${BACKUP_DIR} -type f -iname '*_zammad_files.tar.gz' | sed -e "s#${BACKUP_DIR}/##g" -e "s#_zammad_files.tar.gz##g" | sort)"
  240. if [ "${DB_ADAPTER}" == "postgresql" ]; then
  241. DB_FILE_EXT="psql"
  242. elif [ "${DB_ADAPTER}" == "mysql2" ]; then
  243. DB_FILE_EXT="mysql"
  244. fi
  245. RESTORE_DB_DATES="$(find ${BACKUP_DIR} -type f -iname "*_zammad_db.${DB_FILE_EXT}.gz" | sed -e "s#${BACKUP_DIR}/##g" -e "s#_zammad_db.${DB_FILE_EXT}.gz##g" | sort)"
  246. }
  247. function choose_restore_date () {
  248. if [ -n "${1}" ]; then
  249. RESTORE_FILE_DATE="${1}"
  250. else
  251. echo -e "Enter file date to restore: \n${RESTORE_FILE_DATES}"
  252. read -p 'File date: ' RESTORE_FILE_DATE
  253. fi
  254. if [ ! -f "${BACKUP_DIR}/${RESTORE_FILE_DATE}_zammad_files.tar.gz" ];then
  255. echo -e "File ${BACKUP_DIR}/${RESTORE_FILE_DATE}_zammad_files.tar.gz does not exist! \nRestore aborted!"
  256. exit 1
  257. fi
  258. if [ -n "${1}" ]; then
  259. RESTORE_DB_DATE="${1}"
  260. else
  261. echo -e "Enter db date to restore: \n${RESTORE_DB_DATES}"
  262. read -p 'DB date: ' RESTORE_DB_DATE
  263. fi
  264. if [ ! -f "${BACKUP_DIR}/${RESTORE_DB_DATE}_zammad_db.${DB_FILE_EXT}.gz" ];then
  265. echo -e "File ${BACKUP_DIR}/${RESTORE_DB_DATE}_zammad_db.${DB_FILE_EXT}.gz does not exist! \nRestore aborted!"
  266. exit 1
  267. fi
  268. }
  269. function detect_initcmd () {
  270. if [ -n "$(which systemctl 2> /dev/null)" ]; then
  271. INIT_CMD="systemctl"
  272. elif [ -n "$(which initctl 2> /dev/null)" ]; then
  273. INIT_CMD="initctl"
  274. else
  275. function sysvinit () {
  276. service $2 $1
  277. }
  278. INIT_CMD="sysvinit"
  279. fi
  280. if [ "${DOCKER}" == "yes" ]; then
  281. INIT_CMD="initctl"
  282. fi
  283. if [ "${DEBUG}" == "yes" ]; then
  284. echo "INIT CMD = ${INIT_CMD}"
  285. fi
  286. }
  287. function start_zammad () {
  288. echo "# Starting Zammad"
  289. ${INIT_CMD} start zammad
  290. }
  291. function stop_zammad () {
  292. echo "# Stopping Zammad"
  293. ${INIT_CMD} stop zammad
  294. if [ "$?" != "0" ]; then
  295. echo -e "\n\n # WARNING: You don't seem to have administrative permissions!"
  296. echo -e " #-> This may be fine if you're on a source code installation."
  297. echo -e " #-> Please ensure that Zammad is NOT running - otherwise restore will FAIL.\n"
  298. fi
  299. }
  300. function restore_zammad () {
  301. if ! command -v zammad > /dev/null; then
  302. # See #3160 for the reasons of this :>
  303. restore_files
  304. fi
  305. if [ "${DB_ADAPTER}" == "postgresql" ]; then
  306. echo "# Checking requirements"
  307. if ! id "zammad" &> /dev/null; then
  308. echo "# ERROR: User 'zammad' is not present, but should be by default! #"
  309. echo "# Restoration was NOT successful, exiting ..."
  310. exit 1
  311. fi
  312. echo "# ... Dropping current database ${DB_NAME}"
  313. # This step is only needed for some pgsql dumps, as they don't provide a drop table statement which will cause
  314. # relation errors during restoration (as on package installation there's always an initialized database)
  315. if command -v zammad > /dev/null; then
  316. zammad config:set DISABLE_DATABASE_ENVIRONMENT_CHECK=1
  317. zammad run rake db:drop
  318. zammad config:set DISABLE_DATABASE_ENVIRONMENT_CHECK=0
  319. else
  320. DISABLE_DATABASE_ENVIRONMENT_CHECK=1 ${ZAMMAD_DIR}/bin/rake db:drop
  321. fi
  322. echo "# ... Creating database ${DB_NAME} for owner ${DB_USER}"
  323. if command -v zammad > /dev/null; then
  324. # We'll skip this part for docker installations
  325. su -c "psql -c \"CREATE DATABASE ${DB_NAME} OWNER ${DB_USER};\"" postgres
  326. else
  327. ${ZAMMAD_DIR}/bin/rake db:create
  328. fi
  329. echo "# Restoring PostgreSQL DB"
  330. create_pgpassfile
  331. # We're removing uncritical dump information that caused "ugly" error
  332. # messages on older script versions. These could safely be ignored.
  333. zcat ${BACKUP_DIR}/${RESTORE_DB_DATE}_zammad_db.${DB_FILE_EXT}.gz | \
  334. sed '/^CREATE EXTENSION IF NOT EXISTS plpgsql/d'| \
  335. sed '/^COMMENT ON EXTENSION plpgsql/d'| \
  336. psql -q -b -o /dev/null \
  337. ${DB_HOST:+--host $DB_HOST} ${DB_PORT:+--port $DB_PORT} ${DB_USER:+--username $DB_USER} --dbname ${DB_NAME}
  338. state=$?
  339. if [[ ("${state}" == "1") || ( "${state}" == "2") || ( "${state}" == "3") ]]; then
  340. # We're checking for critical restoration errors
  341. # It may not cover all possible errors which is out of scope of this script
  342. echo -e "\n\n # ERROR(${state}) - Database credentials are wrong or database server configuration is invalid."
  343. echo -e " #-> RESTORE WAS NOT SUCCESSFUL"
  344. exit 2
  345. fi
  346. elif [ "${DB_ADAPTER}" == "mysql2" ]; then
  347. echo "# Restoring MySQL DB"
  348. zcat < ${BACKUP_DIR}/${RESTORE_DB_DATE}_zammad_db.${DB_FILE_EXT}.gz | mysql -u${DB_USER} -p${DB_PASS} ${DB_NAME}
  349. state=$?
  350. if [ "${state}" != "0" ]; then
  351. echo -e "\n\n # ERROR(${state}) - Database credentials are wrong or database server configuration is invalid."
  352. echo -e " #-> RESTORE WAS NOT SUCCESSFUL"
  353. exit 2
  354. fi
  355. else
  356. echo -e "\n\n # ERROR - Database type or database.yml incorrect. Unsupported database type found."
  357. echo -e " #-> RESTORE WAS NOT SUCCESSFUL"
  358. exit 2
  359. fi
  360. if command -v zammad > /dev/null; then
  361. # See #3160 for the reasons of this :>
  362. restore_files
  363. fi
  364. # Ensure all data is loaded from the restored database and not the cache of the previous system state
  365. echo "# Clearing Cache ..."
  366. if command -v zammad > /dev/null; then
  367. zammad run rails r "Rails.cache.clear"
  368. else
  369. ${ZAMMAD_DIR}/bin/rails r "Rails.cache.clear"
  370. fi
  371. }
  372. function restore_files () {
  373. echo "# Restoring Files"
  374. tar -C / --overwrite -xzf ${BACKUP_DIR}/${RESTORE_FILE_DATE}_zammad_files.tar.gz
  375. state=$?
  376. if [[ ($state == '1') || ($state == '2') ]]; then
  377. echo "# ERROR(${state}) - File restore reported an error."
  378. echo "- Check file permissions, and ensure Zammad IS NOT running, and try again."
  379. echo -e " \n# RESTORE WAS NOT SUCCESSFUL"
  380. exit 1
  381. fi
  382. echo "# Ensuring correct file permissions ..."
  383. chown -R zammad:zammad ${ZAMMAD_DIR}
  384. }
  385. function kind_exit () {
  386. # We're nice to our admin and bring Zammad back up before exiting
  387. start_zammad
  388. exit 1
  389. }
  390. function db_helper_alter_user () {
  391. # Get DB credentials
  392. get_db_credentials
  393. if [ "${DB_PASS}x" == "x" ]; then
  394. echo "# Found an empty password - I'll be fixing this for you ..."
  395. DB_PASS="$(tr -dc A-Za-z0-9 < /dev/urandom | head -c10)"
  396. sed -e "s/.*adapter:.*/ adapter: ${DB_ADAPTER}/" \
  397. -e "s/.*username:.*/ username: ${DB_USER}/" \
  398. -e "s/.*password:.*/ password: ${DB_PASS}/" \
  399. -e "s/.*database:.*/ database: ${DB_NAME}/" < ${ZAMMAD_DIR}/contrib/packager.io/database.yml.pkgr > ${ZAMMAD_DIR}/config/database.yml
  400. echo "# ... Fixing permission database.yml"
  401. chown zammad:zammad ${ZAMMAD_DIR}/config/database.yml
  402. fi
  403. if [ "${DB_USER}x" == "x" ]; then
  404. echo "ERROR - Your configuration file does not seem to contain a username."
  405. echo "Aborting the script - double check your installation."
  406. kind_exit
  407. fi
  408. if [ "${DB_ADAPTER}" == "postgresql" ]; then
  409. if [[ ("${DB_HOST}" == "localhost") || "${DB_HOST}" == "127.0.0.1" || "${DB_HOST}" == "::1" ]]; then
  410. # Looks like a local pgsql installation - let's continue
  411. su -c "psql -c \"ALTER USER ${DB_USER} WITH PASSWORD '${DB_PASS}';\"" postgres
  412. state=$?
  413. else
  414. echo "You don't seem to be using a local PostgreSQL installation."
  415. echo "This script does not support your installation. No changes were done."
  416. kind_exit
  417. fi
  418. else
  419. echo "You don't seem to use PostgreSQL. This script does not support your installation."
  420. echo "No changes were done."
  421. kind_exit
  422. fi
  423. if [ "${state}" != "0" ]; then
  424. echo "ERROR - Our previous command returned an unhandled error code."
  425. echo "Check above command output. Please consult https://community.zammad.org if you can't solve this issue on your own."
  426. kind_exit
  427. fi
  428. }
  429. function start_backup_message () {
  430. echo -e "\n# Zammad backup started - $(date)!\n"
  431. }
  432. function start_restore_message () {
  433. echo -e "\n# Zammad restore started - $(date)!\n"
  434. }
  435. function start_helper_message () {
  436. echo -e "\n # This helper script sets the current Zammad user password on your postgresql server."
  437. }
  438. function finished_backup_message () {
  439. echo -e "\n# Zammad backed up successfully - $(date)!\n"
  440. }
  441. function finished_restore_message () {
  442. echo -e "\n# Zammad restored successfully - $(date)!\n"
  443. }