Bash Shell Script
No comment
Download Count: 114
Date Added: Monday, 04-Jul-11 00:04:44 CDT
Tags: bash shell script, file backup, linux, gzip, tar
A simple bash script to back up (tar and gzip) all files in a folder. Can be run from command line or from cron. Resulting gzipped file name will be based on date the script was run.
Make sure the file is executable (chmod 755 file_backup.sh).
File Name: file_backup.sh - Code Type: Bash
#!/bin/bash ## A simple bash script to back up (tar and compress) all files in a folder ## name for the backup file based on date name=file_backup-$(date +%Y%m%d).tar ## directory containing the files to be backed up directory=/home/fred ## where to store backup file - wherever that is? backup_directory=/root ## change to backup directory cd $backup_directory ## create empty file so tar can create new archive with it touch empty.txt ## create the backup file and remove empty file tar --create --verbose --remove-files --file=$name empty.txt ## archive all files for file in `ls $directory` do tar --append --verbose --file=$name $directory/$file done ## finally compress the tar file gzip $name exit $?
Parsed in 0.051 seconds - Rate: 13.79 KB/s - GeSHi version: 1.0.8.10
Hope you find this helpful! If you have any questions, please leave a comment.