Backing up a designated folder with cyclical repetition
Hey, today I will introduce you to a small bash script, which backs up a given folder on our server at a given time or day, possibly every few minutes.
script:
1 2 3 4 5 6 7 | #!/bin/bash DATA=`date +"%b-%d-%y"` NAZWAPLIKU="backup-$DATA.tar.gz" ZRODLO="/home/linux" KDOCELOWY="/home/backup" tar -cpzf $KDOCELOWY/$NAZWAPLIKU $ZRODLO |
A catalog should be provided with the SOURCE, what we want to pack, while for KDOBELOWY we provide the path to the folder, where the copy should be. File should be given permissions 700.
Permissions:
1 | chmod 700 nazwaskryptu.sh |
If we want to, for the script to run itself, add it to the cron, (we enter in the terminal):
1 | crontab -e |
Then add it to the file, which we opened with the command above:
1 | 00 01 * * * /sciezka_do_skryptu/nazwaskryptu.sh |
Thanks to this, our script will run every day at 01:00 in the night