# Restore failing from same new system

**URL:** https://community.zammad.org/t/restore-failing-from-same-new-system/8146
**Category:** Technical assistance
**Created:** [November 20, 2021, 2:36pm UTC](https://community.zammad.org/t/restore-failing-from-same-new-system/8146 "2021-11-20T14:36:53Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Lapotor](https://community.zammad.org/user_avatar/community.zammad.org/lapotor/32/874_2.png) [@Lapotor](https://community.zammad.org/u/Lapotor)
#### Post date: [November 20, 2021, 2:36pm UTC](https://community.zammad.org/t/restore-failing-from-same-new-system/8146/1 "2021-11-20T14:36:53Z")

</div>

### Infos:

- Used Zammad version: 5.0.2
- Installation method (source, package, ..): package
- Operating system: ubuntu 20.04
- Database + version: postgres 12.9
- Elasticsearch version: elasticsearch 7.15.2

### Expected behavior:

- Install zammad (hetzner cloud)
- After install create backup (with #2508)
- After backup restore same backup directly
- Restoreing successful

### Actual behavior:

- Backup folder set as in #2508
- try restore this backup
  - when restoreing with zammad user:

```auto
$ sudo -u zammad -H /opt/zammad/contrib/backup/zammad_restore.sh

# Zammad restored started - Sat 20 Nov 2021 01:45:26 PM UTC!

The restore will delete your current config and database!
Be sure to have a backup available!

Enter 'yes' if you want to proceed!
Restore?: yes
Enter file date to restore:
20211120134351
File date: 20211120134351
Enter db date to restore:
20211120134351
DB date: 20211120134351
# Stopping Zammad
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to stop 'zammad.service'.
Authenticating as: root
Password: Failed to stop zammad.service: Connection timed out
See system logs and 'systemctl status zammad.service' for details.
# Checking requirements
polkit-agent-helper-1: pam_authenticate failed: Authentication failure
# ... Dropping current database zammad
PG::ObjectInUse: ERROR: database "zammad" is being accessed by other users
DETAIL: There are 6 other sessions using the database.
Couldn't drop database 'zammad'
rake aborted!
ActiveRecord::StatementInvalid: PG::ObjectInUse: ERROR: database "zammad" is being accessed by other users

```

- When restoring with `root` user:

```auto
$ /opt/zammad/contrib/backup/zammad_restore.sh

# Zammad restored started - Sat 20 Nov 2021 01:48:10 PM UTC!

The restore will delete your current config and database!
Be sure to have a backup available!

Enter 'yes' if you want to proceed!
Restore?: yes
Enter file date to restore:
20211120134351
File date: 20211120134351
Enter db date to restore:
20211120134351
DB date: 20211120134351
# Stopping Zammad
# Checking requirements
# ... Dropping current database zammad
Dropped database 'zammad'
# ... Creating database zammad for owner zammad
CREATE DATABASE
# Restoring PostgreSQL DB
psql: error: FATAL: Peer authentication failed for user "zammad"
# Restoring Files
# Ensuring correct file rights ...
# Clearing Cache ...
# Starting Zammad

# Zammad restored successfully - Sat 20 Nov 2021 01:48:36 PM UTC!

```

### Steps to reproduce the behavior:

- Install zammad (hetzner cloud)
- After install create backup (with #2508)
- After backup restore same backup directly

---

<div class="post-metadata">

### Author: ![sebastianlenz](https://community.zammad.org/letter_avatar_proxy/v4/letter/s/13edae/32.png) [@sebastianlenz](https://community.zammad.org/u/sebastianlenz)
#### Post date: [January 22, 2022, 12:04pm UTC](https://community.zammad.org/t/restore-failing-from-same-new-system/8146/2 "2022-01-22T12:04:38Z")

</div>

Hi there,  
i detected there is an error in /opt/zammad/contrib/backup/functions

I changed

```auto
zcat < ${BACKUP_DIR}/${RESTORE_DB_DATE}_zammad_db.${DB_FILE_EXT}.gz \
      | psql ${DB_HOST:+--host $DB_HOST} ${DB_PORT:+--port $DB_PORT} ${DB_USER:+--username $DB_USER} --dbname ${DB_NAME}

```

to

```auto
zcat < ${BACKUP_DIR}/${RESTORE_DB_DATE}_zammad_db.${DB_FILE_EXT}.gz \
      | su -c "psql ${DB_HOST:+--host $DB_HOST} ${DB_PORT:+--port $DB_PORT} ${DB_USER:+--username $DB_USER} --dbname ${DB_NAME}" zammad

```

and everything works like expected.

Greetings  
Sebastian

---

<div class="post-metadata">

### Author: ![MrGeneration](https://community.zammad.org/user_avatar/community.zammad.org/mrgeneration/32/9260_2.png) [@MrGeneration](https://community.zammad.org/u/MrGeneration)
#### Post date: [January 22, 2022, 1:56pm UTC](https://community.zammad.org/t/restore-failing-from-same-new-system/8146/3 "2022-01-22T13:56:55Z")

</div>

This is not an error but working as designed.  
You’re supposed to restore as root user.

---

<div class="post-metadata">

### Author: ![torsten](https://community.zammad.org/user_avatar/community.zammad.org/torsten/32/4420_2.png) [@torsten](https://community.zammad.org/u/torsten)
#### Post date: [February 7, 2022, 12:41pm UTC](https://community.zammad.org/t/restore-failing-from-same-new-system/8146/4 "2022-02-07T12:41:05Z")

</div>

Hi @MrGeneration

I am trying to restore a backup on a different server as root user - as you recommended - but I get the same `psql: error: FATAL: Peer authentication failed for user "zammad"` error:

```auto
root@zammad-test:/opt/zammad/contrib/backup# ./zammad_restore.sh

# Zammad restored started - Mon 07 Feb 2022 12:28:40 PM UTC!

The restore will delete your current config and database!
Be sure to have a backup available!

Enter 'yes' if you want to proceed!
Restore?: yes
Enter file date to restore:
20220204002101
File date: 20220204002101
Enter db date to restore:
20220204002101
DB date: 20220204002101
# Stopping Zammad
# Checking requirements
# ... Dropping current database zammad
Dropped database 'zammad'
# ... Creating database zammad for owner zammad
CREATE DATABASE
# Restoring PostgreSQL DB
psql: error: FATAL: Peer authentication failed for user "zammad"
# Restoring Files
# Ensuring correct file rights ...
# Clearing Cache ...
# Starting Zammad

# Zammad restored successfully - Mon 07 Feb 2022 12:28:58 PM UTC!

```

@sebastianlenz solution seems to work.

---

<div class="post-metadata">

### Author: ![MrGeneration](https://community.zammad.org/user_avatar/community.zammad.org/mrgeneration/32/9260_2.png) [@MrGeneration](https://community.zammad.org/u/MrGeneration)
#### Post date: [February 7, 2022, 12:49pm UTC](https://community.zammad.org/t/restore-failing-from-same-new-system/8146/5 "2022-02-07T12:49:35Z")

</div>

Update your installation to last possible and read the documentation:  
[https://docs.zammad.org/en/latest/appendix/backup-and-restore/index.html](https://docs.zammad.org/en/latest/appendix/backup-and-restore/index.html)

Please also try to not mention me directly.  
I am receiving a huge amount of notifications.

---

<div class="post-metadata">

### Author: ![system](https://community.zammad.org/uploads/default/original/1X/5c5afaea2d23f811dbec33cd4edb02fa29d3262f.png) [@system](https://community.zammad.org/u/system)
#### Post date: [June 7, 2022, 12:50pm UTC](https://community.zammad.org/t/restore-failing-from-same-new-system/8146/6 "2022-06-07T12:50:17Z")

</div>

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.
