File size: 857 Bytes
054900e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/bin/sh -e

# The directory where backups are stored
BACKUP_DIRECTORY="/backups"

# Check if a file name was provided as a parameter
if [ $# -eq 0 ]; then
  echo "No file name provided. Please provide a file name to check."
  exit 1
fi

# The file name is taken from the first argument provided to the script
file_name="$1"

# Full path to the file
full_file_path="${BACKUP_DIRECTORY}/${file_name}"

# Check if the file exists
if [ -f "$full_file_path" ]; then
  echo "File ${file_name} exists."
else
  echo "File ${file_name} does not exist."
  exit 1
fi

# MongoDB connection parameters
MONGO_URI="${MONGO_URI}"

echo "Dropping the database..."
mongo "$MONGO_URI" --eval "db.dropDatabase()"

echo "Restoring the database from the backup..."
gunzip -c "${full_file_path}" | mongorestore --archive --uri="$MONGO_URI"

echo "Backup restored successfully."