Repository navigation
Expand file tree
/
Copy pathbackup.sh
More file actions
executable file
·79 lines (66 loc) · 2.34 KB
/
Copy pathbackup.sh
File metadata and controls
executable file
·79 lines (66 loc) · 2.34 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env bash
# Backup Script for Google Drive using rclone
#
# Author: madrian
# GitHub: https://github.com/madrian/rclone-backup
set -euo pipefail
# Folder configuration
# Add / Remove source folders to backup using absolute path.
SOURCE_FOLDERS=(
"/home/adrian/sample"
"/home/adrian/sample2"
"/home/adrian/sample3"
)
# Adjust these paths to match your rclone remote configuration.
# The source folders will be copied/sync under the target parent folder.
# The versioned copies of deleted/updated files will be stored under the archive parent folder.
TARGET_PARENT="gdrive:/sample"
ARCHIVE_PARENT="gdrive:/sample-archive/deleted"
# End of folder configuration
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
LOG_DIR="${SCRIPT_DIR}/out"
IGNORE_FILE="${SCRIPT_DIR}/rclone-ignore.txt"
BACKUP_DATE=$(date +"%Y-%m-%d")
BACKUP_TIME=$(date +"%H%M%S")
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
LOG_FILE="${LOG_DIR}/backup_${TIMESTAMP}.log"
mkdir -p "$LOG_DIR"
exec > "$LOG_FILE" 2>&1
echo "========================================================="
echo " Starting Backup Sync: $(date)"
echo "========================================================="
for SRC in "${SOURCE_FOLDERS[@]}"; do
FOLDER_NAME=$(basename "$SRC")
echo "---------------------------------------------------------"
echo "Processing: ${FOLDER_NAME}"
echo "Source: ${SRC}/"
echo "Destination: ${TARGET_PARENT}/${FOLDER_NAME}/"
echo "Archive: ${ARCHIVE_PARENT}/${FOLDER_NAME}/${BACKUP_DATE}/"
echo "---------------------------------------------------------"
if [ ! -d "$SRC" ]; then
echo "Source directory '${SRC}' not found. Skipping..."
continue
fi
# Adjust these settings for performance tuning
CHECKERS=4
TRANSFERS=2
CHUNK_SIZE="32M"
TPS_LIMIT=8
rclone sync \
"${SRC}/" \
"${TARGET_PARENT}/${FOLDER_NAME}/" \
--create-empty-src-dirs \
--checkers="${CHECKERS}" \
--transfers="${TRANSFERS}" \
--tpslimit="${TPS_LIMIT}" \
--fast-list \
--drive-chunk-size="${CHUNK_SIZE}" \
--exclude-from "$IGNORE_FILE" \
--delete-excluded \
--backup-dir "${ARCHIVE_PARENT}/${FOLDER_NAME}/${BACKUP_DATE}" \
--suffix "_${BACKUP_TIME}" \
-v
done
echo "========================================================="
echo " Backup Finished Successfully: $(date)"
echo "========================================================="