-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostgressql.sh
More file actions
38 lines (28 loc) · 1.06 KB
/
postgressql.sh
File metadata and controls
38 lines (28 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
# This IS BETA Version :)))
# Set variables
file_name=$(date +%Y%m%d_%H%M%S)
password=""
database_name=""
user="postgres" # Adjust if using a different user
host="localhost" # Adjust if the database is on a different server
port="5432" # Adjust if using a different port
directory_to_save="/path/PG_Backup"
webhook_url=""
# Ensure the backup directory exists
mkdir -p "$directory_to_save"
# Backup PostgreSQL database
echo "Starting PostgreSQL Backup..."
pg_dump -u "$user" -h "$host" -p "$port" -d "$database_name" > "$directory_to_save/$file_name.sql" \
2> "$directory_to_save/$file_name_error.log"
# Check if the backup was successful
if [ $? -eq 0 ]; then
echo "PostgreSQL Backup completed successfully."
# Send notification via Discord webhook
bash discord.sh --webhook-url "$webhook_url" --file "$directory_to_save/$file_name.sql"
# Clean up SQL backup file (optional)
# rm -f "$directory_to_save/$file_name.sql"
echo "Cleanup completed."
else
echo "PostgreSQL Backup failed. Check error log: $directory_to_save/$file_name_error.log"
fi