How to backup Files and Directories Date-wise using bash script automatically

Backup Files and Directories in Linux Using bash script

bash

This is for only System Administrator. One of the simplest ways to backup a system is using a shell script. We will create a shell script using variables, The tar command and the date command to create a dated backup file of a directory, with its sub-directories.

#!/bin/bash
####################################
#                     Backup script.                        #
####################################

# What to backup. 
backup_files="/var/www/html"

# Where to backup to.
dest="/home/user/Desktop"

# Create archive filename.
day=$(date +%Y_%m_%d_%H_%M)
backname="Backup"

archive_file="$backname-$day.tgz"

# Print start status message.
echo "Backing up $backup_files to $dest/$archive_file"
date
echo

# Backup the files using tar.
tar czf $dest/$archive_file $backup_files

# Print end status message.
echo
echo "Backup finished"
date

# Long listing of files in $dest to check file sizes.
ls -lh $dest

#####################################################



SHARE

Ibrar Ansari

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment