Last active
November 19, 2019 09:22
-
-
Save Fieel/02c45df9e10db6bdcba27cafc3c0607b to your computer and use it in GitHub Desktop.
Backup your Raspbian OS in a remote NAS in your LAN, compressed into a .tar.gz archive.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# @uthor: Filipe Madureira | |
# Backups a compressed raspbian system to a remote NAS location. | |
# | |
NAS_PATH="//server/share" | |
MOUNT_PATH="/mnt/remote-nas" | |
BACKUP_PATH=$MOUNT_PATH"/backups/" | |
TEMP_PATH="/tmp/backup" | |
LOG_PATH="/var/log/backup.log" | |
DATE=$(date +"%Y-%m-%d_%H%M") | |
# Log backup start | |
echo $DATE": Backup START" >> $LOG_PATH | |
mkdir $MOUNT_PATH | |
mkdir $TEMP_PATH | |
# Mount remote NAS | |
sudo mount -t cifs -o guest $NAS_PATH $MOUNT_PATH | |
# Start by copying all the filesystem and storing it in the tmp directory | |
sudo /usr/bin/rsync -Pavzh --delete --exclude $TEMP_PATH --exclude /run --exclude /var/run --exclude /sys --exclude /mnt --exclude /proc --exclude /dev --exclude /boot --exclude /media --exclude /mnt --exclude /lost+found / $TEMP_PATH | |
# Compress even more the backup into a .tar.gz file | |
sudo tar -cpzf $BACKUP_PATH$DATE.tar.gz $TEMP_PATH | |
# Remove the tmp files | |
sudo rm -r $TEMP_PATH | |
# Unmount remote NAS | |
sudo umount $MOUNT_PATH | |
# Log backup end | |
echo "$(date +"%Y-%m-%d_%H%M %T"): Backup END" >> $LOG_PATH |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment