Here is my issue: I have to write a shell script that archives pictures stored in a directory. within my /home/pictures directory, jpegs get saved. Once the folder gets large enough (100MB), I would like to make a tar.gz archive all the files located in the directory, and move them to /home/archives. How would I go about writing a shell script/cron job to perform this?
here is what I have so far: Code: #!/bin/bash # Backup Script echo "\nWelcome to the backup script\n" cd /home/images if [$du -h /home/images] >= 100MB ; then tar -pczf `date`.tar.gz /home/pictures/backup fi exit 0; This doesn't work right.
Try this Code: #!/bin/bash # Backup Script echo "\nWelcome to the backup script\n" path="/home/images" if [ `du -ms $path` > 1000 ] ; then find $path > /tmp/list.txt tar -T /tmp/list.txt -pczf `date`.tar.gz for i in `cat /tmp/list.txt`; do rm -rf $i done fi exit 0;