script bash membuat backup otomatis


Kemarin cari cari buat backup otomatis😀 akirnya nemu cara membuat backup otomatis lengkap dengan nama file yang sesuai dengan tanggal, ini dibuat menggunakan script bash pada linux, nah, tinggal digabungkan dengan CRONTAB, sehingga script backup ini dapat berjalan sesuai tanggal yang diinginkan secara otomatis ( misalkan, setiap tanggal 1 ).

#!/bin/bash
# /usr/bin/backup
# Backup script for Directory X and PHP Include Files
# The following MySQL databses are also backed up:
# DB_NAME
#
# DATE: 05/05/2003

#################################
# Assign DTG and Date variables #
# to $a & $b respectively       #
#################################
a=$(date +%T-%d_%m_%Y)
b=$(date +%d_%m_%Y)

########################################
# Backup Site Directory – files and db #
########################################
mkdir /directory/to/backup/to/$b/

# To copy only – nil archiving nil compression uncomment the next line
cp -i -p -R /directory/to/be/backed/up /directory/to/backup/to/$b/name_of_bup.$a

# Archiving using tar, compression using bz2 all permissions kept in tact
tar pcjf “/directory/to/backup/to/$b/name_of_bup_file.tar.bz2” “/directory/to/be/backed/up”
mysqldump –password=password DB_NAME > /directory/to/backup/to/$b/name_of_bup_file.sql

echo “Back up of the X directory is complete”

tinggal execute file.. dan backuppun siap

script bash membuat backup otomatis

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s