backup scripts using rsync
This commit is contained in:
parent
ce104c6c26
commit
36e5a68b54
49
rsync-cron/Readme-rync.md
Normal file
49
rsync-cron/Readme-rync.md
Normal file
@ -0,0 +1,49 @@
|
||||
# Rync job for Backups
|
||||
|
||||
a: Archive mode used to copy files recursively while preserving symbolic links, file permissions and ownership, and timestamps.
|
||||
v: Verbose mode to get more detailed information on the file transfer process.
|
||||
z: Enable file compression. This option can be omitted when transferring files locally but is incredibly useful when sending data over the network to reduce the amount of it transmitted.
|
||||
H: Preserve hard links.
|
||||
P: Show the progress of the data transfer.
|
||||
--dry-run or -n - Perform a trial run without making any changes.
|
||||
|
||||
```bash
|
||||
# create initial full backup
|
||||
rsync -a --delete "/mnt/c/Users/dechert/git/swagup-server/rsync-cron/test-folder" "/mnt/c/Users/dechert/git/swagup-server/rsync-cron/backup-folder"
|
||||
|
||||
|
||||
chmod +x /usr/local/bin/backup.sh
|
||||
```
|
||||
|
||||
Testing:
|
||||
- deleted files
|
||||
- restore old backup
|
||||
- incremental
|
||||
- 234M ./test-backup-folder-time
|
||||
- du -h ~/backup_test
|
||||
|
||||
## Rsync Time backup
|
||||
https://github.com/laurent22/rsync-time-backup
|
||||
|
||||
```bash
|
||||
bash rsync_tmbackup.sh --log-dir "/home/dechert/rsync_backup_logs" /mnt/c/Users/dechert/git/swagup-server/rsync-cron/test-folder /mnt/c/Users/dechert/git/swagup-server/rsync-cron/test-backup_folder_time
|
||||
|
||||
# run 1 time to create backup marker
|
||||
mkdir -p -- "/mnt/c/Users/dechert/git/swagup-server/rsync-cron/test-backup_folder_time" ; touch "/mnt/c/Users/dechert/git/swagup-server/rsync-cron/test-backup_folder_time/backup.marker"
|
||||
|
||||
# run inside linux
|
||||
bash rsync_tmbackup.sh --log-dir "/home/dechert/rsync_backup_logs" ~/backup_test/test-folder ~/backup_test/test-backup-folder-time
|
||||
|
||||
# Restore backup
|
||||
rsync -aP ~/backup_test/test-backup-folder-time/latest ~/backup_test/test-folder --dry-run
|
||||
|
||||
# on synology
|
||||
bash rsync_tmbackup.sh /volume2/homes/admin/marceload_backup/test-folder /volume2/homes/admin/marceload_backup/backup-folder
|
||||
|
||||
```
|
||||
|
||||
### Logging
|
||||
|
||||
default log location: `LOG_DIR="$HOME/.$APPNAME"`, e.g. `/home/dechert/.rsync_tmbackup/2025-01-17-123519.log`,
|
||||
`/var/services/homes/admin/.rsync_tmbackup`
|
||||
AUTO_DELETE_LOG -> if no error: log will be deleted
|
9
rsync-cron/create-backup.sh
Normal file
9
rsync-cron/create-backup.sh
Normal file
@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
BACKUP_DIR="/mnt/c/Users/dechert/git/swagup-server/rsync-cron/test-folder"
|
||||
SOURCE_DIR="/mnt/c/Users/dechert/git/swagup-server/rsync-cron/backup-folder"
|
||||
|
||||
# Create incremental backup with rsync
|
||||
rsync -a --delete --link-dest=$BACKUP_DIR/latest $SOURCE_DIR $BACKUP_DIR/$(date +%F_%T)
|
||||
|
||||
# Update latest symlink
|
||||
ln -sfn $BACKUP_DIR/$(date +%F) $BACKUP_DIR/latest
|
28
rsync-cron/create-incremental-backup.sh
Normal file
28
rsync-cron/create-incremental-backup.sh
Normal file
@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
|
||||
# https://linuxconfig.org/how-to-create-incremental-backups-using-rsync-on-linux
|
||||
# A script to perform incremental backups using rsync
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
# readonly SOURCE_DIR="${HOME}"
|
||||
# readonly BACKUP_DIR="/mnt/data/backups"
|
||||
readonly BACKUP_DIR="/mnt/c/Users/dechert/git/swagup-server/rsync-cron/backup-folder2"
|
||||
readonly SOURCE_DIR="/mnt/c/Users/dechert/git/swagup-server/rsync-cron/test-folder"
|
||||
|
||||
readonly DATETIME="$(date '+%Y-%m-%d_%H:%M:%S')"
|
||||
readonly BACKUP_PATH="${BACKUP_DIR}/${DATETIME}"
|
||||
readonly LATEST_LINK="${BACKUP_DIR}/latest"
|
||||
|
||||
mkdir -p "${BACKUP_DIR}"
|
||||
|
||||
rsync -av --delete \
|
||||
"${SOURCE_DIR}/" \
|
||||
--link-dest "${LATEST_LINK}" \
|
||||
--exclude=".cache" \
|
||||
"${BACKUP_PATH}"
|
||||
|
||||
rm -rf "${LATEST_LINK}"
|
||||
ln -s "${BACKUP_PATH}" "${LATEST_LINK}"
|
4
rsync-cron/create_testing_folders.sh
Normal file
4
rsync-cron/create_testing_folders.sh
Normal file
@ -0,0 +1,4 @@
|
||||
mkdir backup-folder && \
|
||||
mkdir test-folder && \
|
||||
touch test-folder/file1.txt && \
|
||||
test-folder/file1.txt << "some_content"
|
Loading…
x
Reference in New Issue
Block a user