bash Bash Shell Script
Download File Backup ScriptDownload File Backup Script
Download Count: 119
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.055 seconds - Rate: 12.80 KB/s - GeSHi version: 1.0.8.10

Hope you find this helpful! If you have any questions, please leave a comment.


  • PHP
  • Scripts
  • MS
  • Office
  • Templates
  • and
  • Files
  • Assorted
  • Linux
  • Bash
  • Scripts
  • Perl
  • Scripts
  • PDF
  • FIles
  • MS
  • Excel
  • 2003
  • Template
  • employment
  • tools
  • job
  • search
  • tools
  • spreadsheet
  • Job
  • Search
  • Spreadsheet
  • Template
  • bash
  • shell
  • script
  • file
  • backup
  • linux
  • gzip
  • tar
  • File
  • Backup
  • Script
  • Transmission
  • shell
  • script
  • public
  • torrent
  • private
  • torrent
  • Bit
  • Torrent
  • Transmission
  • BitTorrent
  • Completion
  • Script
  • Transmission
  • shell
  • script
  • torrent
  • information
  • Bit
  • Torrent
  • Transmission
  • Bit
  • Torrent
  • Get
  • Torrent
  • Info
  • bash
  • shell
  • script
  • add
  • user
  • samba
  • samba
  • user
  • add
  • samba
  • user
  • linux
  • command
  • line
  • Add
  • System
  • and
  • Samba
  • User
  • geshi
  • pyrocms
  • php
  • codeigniter
  • PyroCMS/CodeIgniter
  • Geshi
  • Helper
  • File
  • geshi
  • pyrocms
  • php
  • codeigniter
  • GeSHi
  • Code
  • Highlighter
  • plugin
  • for
  • PyroCMS
  • perl
  • cgi
  • hit
  • counter
  • Simple
  • Perl
  • Hit
  • Counter
  • pyrocms
  • codeigniter
  • php
  • ip
  • address
  • session
  • userdata
  • PyroCMS
  • IP
  • Address
  • Plugin
  • Soyo
  • SY5SSM
  • Socket
  • 7
  • Motherboard
  • Quick
  • Start
  • Guide
  • Soyo
  • SY5SSM
  • Socket
  • 7
  • Motherboard
  • Quick
  • Start
  • Guide
  • Home
  • web
  • designit
  • supportlinuxphpbash
  • PRIVACY
  • Statement
  • LEGAL
  • Disclaimer
  • Ebay
  • Listings
  • Soyo
  • Motherboard
  • PDF
  • Why
  • I
  • Like
  • the
  • HoneyPi
  • Brand
  • IR
  • Receiver
  • Module
  • for
  • the
  • Raspberry
  • Pi
  • Using
  • GeSHi
  • Highlighter
  • with
  • PyroCMS/CodeIgniter
  • Easy
  • as
  • 1
  • 2
  • 3
  • PHP
  • Stuff
  • Raspberry
  • PI