-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup.sh
More file actions
executable file
·33 lines (25 loc) · 915 Bytes
/
backup.sh
File metadata and controls
executable file
·33 lines (25 loc) · 915 Bytes
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
#!/bin/bash
# Path to the configuration file
CONFIG_FILE="./backup_config.cfg"
# Read the configuration file
if [ -f "$CONFIG_FILE" ]; then
source "$CONFIG_FILE"
else
echo "Configuration file not found: $CONFIG_FILE"
exit 1
fi
# Convert the FOLDERS string into an array
IFS=',' read -ra FOLDERS <<< "$FOLDERS"
# Get the current date in Y-m-d format
CURRENT_DATE=$(date +"%Y-%m-%d")
# Loop through the folders
for FOLDER in "${FOLDERS[@]}"; do
# Get the folder name without the full path
FOLDER_NAME=$(basename "$FOLDER")
# Define the backup file name
BACKUP_FILE_NAME="${FOLDER_NAME}_backup_${CURRENT_DATE}.zip"
# Create the zip archive of the folder content
zip -r "${BACKUP_DIR}/${BACKUP_FILE_NAME}" "$FOLDER"
# Delete backups older than RETENTION_DAYS days
find "${BACKUP_DIR}/" -name "${FOLDER_NAME}_backup_*.zip" -type f -mtime +$RETENTION_DAYS -delete
done