Very simple scipt to backup a snapshot of a folder in linux. It retains user permission and ownership. Backups are stored in a specified directory, rotated to maintain a specified number of instances, and named according to the date of the backup.
If you are locking for a solid backup script, try this --> http://www.mikerubel.org/computers/rsync_snapshots/
- Creates compressed backups (
*.tgz
). - Retains user permissions and ownership.
- Rotates backups to maintain a specified number of instances.
- Supports exclusion of certain directories (
*/@eaDir
,*/#recycle
,*/@sharebin
).
-
Clone the repository:
git clone https://github.com/juehv/lnx-folder-bkp.git cd lnx-folder-bkp
-
Make the script executable:
chmod +x bbackup-folder.sh
-
Install required dependencies:
- Install rsync and tar on the system.
- Ensure
pv
(Pipe Viewer) is installed for progress bars during backups.
-
Adjust configuration:
- Modify
SOURCE_DIR
,SNAPSHOT_DIR
,BACKUP_DIR
, andNUM_BACKUPS
variables inbackup-folder.sh
as per your requirements.
- Modify
-
Run the script as root:
sudo ./backup-folder.sh
-
Automated Backup Setup (Cron Job):
Add the following line to your crontab (
crontab -e
) to run the backup script every Sunday at midnight:0 0 * * 0 /path/to/backup-folder.sh
This example schedules the script to run every week (
0 0 * * 0
), which means at 00:00 (midnight) on Sunday (0
represents Sunday in the cron syntax).
This project is licensed under the MIT License. See the LICENSE file for details.