|
906 | 906 | if is_this_installed postgresql-common |
907 | 907 | then |
908 | 908 | cd /tmp |
909 | | - if sudo -u postgres psql -c "SELECT 1 AS result FROM pg_database WHERE datname='$NCDB'" | grep "1 row" > /dev/null |
| 909 | + # Test connection to PostgreSQL |
| 910 | + if ! sudo -u postgres psql -c "\q" |
910 | 911 | then |
911 | | - print_text_in_color "$ICyan" "Doing pgdump of $NCDB..." |
912 | | - check_command sudo -u postgres pg_dump -Fc "$NCDB" > "$BACKUP"/nextclouddb.dump |
913 | | - # Import: |
914 | | - # sudo -u postgres pg_restore --verbose --clean --no-acl --no-owner -h localhost -U ncadmin -d nextcloud_db "$BACKUP"/nextclouddb.dump |
| 912 | + # If it fails, trust the 'postgres' user to be able to perform backup |
| 913 | + sed -i "s|local all postgres .*|local all postgres trust|g" /etc/postgresql/*/main/pg_hba.conf |
| 914 | + systemctl restart postgresql.service |
| 915 | + if sudo -u postgres psql -c "SELECT 1 AS result FROM pg_database WHERE datname='$NCDB'" | grep "1 row" > /dev/null |
| 916 | + then |
| 917 | + print_text_in_color "$ICyan" "Doing pgdump of $NCDB..." |
| 918 | + check_command sudo -u postgres pg_dump -Fc "$NCDB" > "$BACKUP"/nextclouddb.dump |
| 919 | + # Import: |
| 920 | + # sudo -u postgres pg_restore --verbose --clean --no-acl --no-owner -h localhost -U ncadmin -d nextcloud_db "$BACKUP"/nextclouddb.dump |
| 921 | + else |
| 922 | + print_text_in_color "$ICyan" "Doing pgdump of all databases..." |
| 923 | + check_command sudo -u postgres pg_dumpall > "$BACKUP"/alldatabases.dump |
| 924 | + fi |
915 | 925 | else |
916 | | - print_text_in_color "$ICyan" "Doing pgdump of all databases..." |
917 | | - check_command sudo -u postgres pg_dumpall > "$BACKUP"/alldatabases.dump |
| 926 | + # If there's no issues, then continue as normal |
| 927 | + if sudo -u postgres psql -c "SELECT 1 AS result FROM pg_database WHERE datname='$NCDB'" | grep "1 row" > /dev/null |
| 928 | + then |
| 929 | + print_text_in_color "$ICyan" "Doing pgdump of $NCDB..." |
| 930 | + check_command sudo -u postgres pg_dump -Fc "$NCDB" > "$BACKUP"/nextclouddb.dump |
| 931 | + # Import: |
| 932 | + # sudo -u postgres pg_restore --verbose --clean --no-acl --no-owner -h localhost -U ncadmin -d nextcloud_db "$BACKUP"/nextclouddb.dump |
| 933 | + else |
| 934 | + print_text_in_color "$ICyan" "Doing pgdump of all databases..." |
| 935 | + check_command sudo -u postgres pg_dumpall > "$BACKUP"/alldatabases.dump |
| 936 | + fi |
918 | 937 | fi |
919 | 938 | fi |
920 | 939 |
|
|
0 commit comments