updating script
All checks were successful
Check scripts syntax / check-scripts-syntax (push) Successful in 22s
All checks were successful
Check scripts syntax / check-scripts-syntax (push) Successful in 22s
This commit is contained in:
@@ -33,27 +33,6 @@ clean_up() {
|
|||||||
|
|
||||||
trap clean_up EXIT
|
trap clean_up EXIT
|
||||||
|
|
||||||
# Check if 7z is installed
|
|
||||||
if ! which 7z; then
|
|
||||||
log "ERROR: 7z is not installed"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if rclone is installed
|
|
||||||
if ! which rclone; then
|
|
||||||
log "ERROR: rclone is not installed"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Create meta directory if it doesn't exist
|
|
||||||
if [ ! -d "$META_DIR" ]; then
|
|
||||||
log "Creating meta directory: $META_DIR"
|
|
||||||
mkdir -p "$META_DIR"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Fix permissions for the meta directory (777 recursively)
|
|
||||||
chmod -R 777 "$META_DIR"
|
|
||||||
|
|
||||||
create_7z() {
|
create_7z() {
|
||||||
local folder="$1"
|
local folder="$1"
|
||||||
local archive_name="$2"
|
local archive_name="$2"
|
||||||
@@ -81,57 +60,86 @@ upload_to_gdrive() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Loop through each folder in the backup source
|
main() {
|
||||||
for folder in "$BACKUP_SOURCE"/*; do
|
# Check if 7z is installed
|
||||||
if [ -d "$folder" ]; then
|
if ! which 7z > /dev/null; then
|
||||||
log "Processing folder: $folder"
|
log "ERROR: 7z is not installed"
|
||||||
# Get the sha256 checksum of the folder
|
exit 1
|
||||||
CHECKSUM=$(find "$folder" -type f -exec sha256sum {} + | sha256sum | awk '{print $1}')
|
fi
|
||||||
META_FILE="$META_DIR/$(basename "$folder").sha256"
|
|
||||||
# Check if the checksum file exists
|
# Check if rclone is installed
|
||||||
if [ -f "$META_FILE" ]; then
|
if ! which rclone > /dev/null; then
|
||||||
# Read the previous checksum from the file
|
log "ERROR: rclone is not installed"
|
||||||
PREV_CHECKSUM=$(cat "$META_FILE")
|
exit 1
|
||||||
# Compare the checksums
|
fi
|
||||||
if [ "$CHECKSUM" != "$PREV_CHECKSUM" ]; then
|
|
||||||
log "Changes detected in $folder - creating new archive"
|
# Create meta directory if it doesn't exist
|
||||||
|
if [ ! -d "$META_DIR" ]; then
|
||||||
|
log "Creating meta directory: $META_DIR"
|
||||||
|
mkdir -p "$META_DIR"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Fix permissions for the meta directory (777 recursively)
|
||||||
|
chmod -R 777 "$META_DIR"
|
||||||
|
|
||||||
|
# Loop through each folder in the backup source
|
||||||
|
for folder in "$BACKUP_SOURCE"/*; do
|
||||||
|
if [ -d "$folder" ]; then
|
||||||
|
log "Processing folder: $folder"
|
||||||
|
# Get the sha256 checksum of the folder
|
||||||
|
CHECKSUM=$(find "$folder" -type f -exec sha256sum {} + | sha256sum | awk '{print $1}')
|
||||||
|
META_FILE="$META_DIR/$(basename "$folder").sha256"
|
||||||
|
# Check if the checksum file exists
|
||||||
|
if [ -f "$META_FILE" ]; then
|
||||||
|
# Read the previous checksum from the file
|
||||||
|
PREV_CHECKSUM=$(cat "$META_FILE")
|
||||||
|
# Compare the checksums
|
||||||
|
if [ "$CHECKSUM" != "$PREV_CHECKSUM" ]; then
|
||||||
|
log "Changes detected in $folder - creating new archive"
|
||||||
|
|
||||||
|
create_7z "$folder" "$TMP_DIR/$(basename "$folder")_$ARCHIVE_NAME"
|
||||||
|
upload_to_gdrive "$TMP_DIR/$(basename "$folder")_$ARCHIVE_NAME"
|
||||||
|
|
||||||
|
# Update the checksum file
|
||||||
|
echo "$CHECKSUM" > "$META_FILE"
|
||||||
|
|
||||||
|
# Remove the temporary archive file
|
||||||
|
log "Removing temporary archive file"
|
||||||
|
rm "$TMP_DIR/$(basename "$folder")_$ARCHIVE_NAME"
|
||||||
|
else
|
||||||
|
log "No changes detected in $folder"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
log "No previous checksum found for $folder - creating new archive"
|
||||||
|
|
||||||
create_7z "$folder" "$TMP_DIR/$(basename "$folder")_$ARCHIVE_NAME"
|
create_7z "$folder" "$TMP_DIR/$(basename "$folder")_$ARCHIVE_NAME"
|
||||||
upload_to_gdrive "$TMP_DIR/$(basename "$folder")_$ARCHIVE_NAME"
|
upload_to_gdrive "$TMP_DIR/$(basename "$folder")_$ARCHIVE_NAME"
|
||||||
|
|
||||||
# Update the checksum file
|
|
||||||
echo "$CHECKSUM" > "$META_FILE"
|
|
||||||
|
|
||||||
|
# Create a checksum file for the folder
|
||||||
|
echo "$CHECKSUM" > "$META_FILE"
|
||||||
|
|
||||||
# Remove the temporary archive file
|
# Remove the temporary archive file
|
||||||
log "Removing temporary archive file"
|
log "Removing temporary archive file"
|
||||||
rm "$TMP_DIR/$(basename "$folder")_$ARCHIVE_NAME"
|
rm "$TMP_DIR/$(basename "$folder")_$ARCHIVE_NAME"
|
||||||
else
|
|
||||||
log "No changes detected in $folder"
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
log "No previous checksum found for $folder - creating new archive"
|
log "Skipping $folder, not a directory"
|
||||||
|
|
||||||
create_7z "$folder" "$TMP_DIR/$(basename "$folder")_$ARCHIVE_NAME"
|
|
||||||
upload_to_gdrive "$TMP_DIR/$(basename "$folder")_$ARCHIVE_NAME"
|
|
||||||
|
|
||||||
# Create a checksum file for the folder
|
|
||||||
echo "$CHECKSUM" > "$META_FILE"
|
|
||||||
|
|
||||||
# Remove the temporary archive file
|
|
||||||
log "Removing temporary archive file"
|
|
||||||
rm "$TMP_DIR/$(basename "$folder")_$ARCHIVE_NAME"
|
|
||||||
fi
|
fi
|
||||||
else
|
log ""
|
||||||
log "Skipping $folder, not a directory"
|
done
|
||||||
fi
|
|
||||||
log ""
|
|
||||||
done
|
|
||||||
|
|
||||||
log "Backup process completed successfully"
|
# Fix permissions for the meta directory (777 recursively)
|
||||||
|
chmod -R 777 "$META_DIR"
|
||||||
|
|
||||||
# Exit with success
|
log "Backup process completed successfully"
|
||||||
exit 0
|
|
||||||
|
|
||||||
|
# Exit with success
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
###########################
|
||||||
|
### Installation script ###
|
||||||
|
###########################
|
||||||
# Function to install a dependency if not already installed
|
# Function to install a dependency if not already installed
|
||||||
install_dependency() {
|
install_dependency() {
|
||||||
local package="$1"
|
local package="$1"
|
||||||
@@ -255,4 +263,7 @@ install_script() {
|
|||||||
|
|
||||||
# Exit with success
|
# Exit with success
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
main "$@"
|
||||||
|
exit 0
|
Reference in New Issue
Block a user