This repository contains a Bash script that creates a compressed image of your SD card, excluding unused space, and uploads it to Nextcloud using rclone
.
The script performs the following tasks:
- Calculates the effective filesystem size: Uses
dumpe2fs
to get the number of used blocks and block size of the specified partition. - Creates an image of the SD card: Uses
dd
to create an image of the SD card, compresses it withgzip
, and saves it in a local backup directory. - Uploads the image to Nextcloud: Uses
rclone
to upload the compressed image to Nextcloud. - Removes the local backup file: Deletes the local backup file after uploading to free up space.
- Operating System: Debian or a compatible Linux distribution
- Tools:
dd
(to create the SD card image)gzip
(to compress the image)dumpe2fs
(to get filesystem information)rclone
(to upload the image to Nextcloud)
- Permissions: The script requires
sudo
permissions fordumpe2fs
anddd
.
-
Install
rclone
: Follow the rclone installation guide for your operating system. -
Configure
rclone
: Runrclone config
to set up a remote for Nextcloud. The remote name should be specified in the script configuration (e.g.,remote:/backup
). -
Edit the Script: Update the following variables in the script as needed:
SD_CARD
: The device name of your SD card (e.g.,/dev/sdX
)PARTITION
: The main partition name (e.g.,/dev/sdX1
)BACKUP_DIR
: The local directory where the image will be saved (e.g.,/path/to/backup
)IMAGE_NAME
: The name of the backup imageRCLONE_REMOTE
: The name of the rclone remote configured for Nextcloud
-
Grant Execute Permissions to the Script:
chmod +x backup_sd_card.sh
Execute the script with superuser permissions:
sudo ./backup_sd_card.sh
- Ensure that the SD card is not mounted during the script execution to avoid conflicts.
- Check the logs for any errors and verify that the backup completed successfully.
If you found this guide helpful and would like to support the project, consider making a donation. Your contributions help maintain and improve this resource.
You can send Bitcoin directly to the following address:
bc1qy0l39zl7spspzhsuv96c8axnvksypfh8ehvx3e
For faster and lower-fee donations, you can use the Lightning Network:
Thank you for your support!
This project is licensed under the MIT License - see the LICENSE file for details.