Backups dengan shell scripts: Perbedaan antara revisi
Loncat ke navigasi
Loncat ke pencarian
kTidak ada ringkasan suntingan |
kTidak ada ringkasan suntingan |
||
Baris 12: | Baris 12: | ||
# | # | ||
#################################### | #################################### | ||
# What to backup. | # What to backup. | ||
backup_files="/home /var/spool/mail /etc /root /boot /opt" | backup_files="/home /var/spool/mail /etc /root /boot /opt" | ||
# Where to backup to. | # Where to backup to. | ||
dest="/mnt/backup" | dest="/mnt/backup" | ||
# Create archive filename. | # Create archive filename. | ||
day=$(date +%A) | day=$(date +%A) | ||
hostname=$(hostname -s) | hostname=$(hostname -s) | ||
archive_file="$hostname-$day.tgz" | archive_file="$hostname-$day.tgz" | ||
# Print start status message. | # Print start status message. | ||
echo "Backing up $backup_files to $dest/$archive_file" | echo "Backing up $backup_files to $dest/$archive_file" | ||
date | date | ||
echo | echo | ||
# Backup the files using tar. | # Backup the files using tar. | ||
tar czf $dest/$archive_file $backup_files | tar czf $dest/$archive_file $backup_files | ||
# Print end status message. | # Print end status message. | ||
echo | echo | ||
echo "Backup finished" | echo "Backup finished" | ||
date | date | ||
# Long listing of files in $dest to check file sizes. | # Long listing of files in $dest to check file sizes. | ||
ls -lh $dest | ls -lh $dest | ||
#Selesai | #Selesai | ||
Revisi per 21 Maret 2021 14.28
Backup directory /var/www pada server
Buat Script pada /usr/bin
$sudo nano /usr/bin/backup-db.sh
Silahkan isi backup-db.sh dengan scripts berikut :
#!/bin/bash #################################### # # Backup to NFS mount script. # #################################### # What to backup. backup_files="/home /var/spool/mail /etc /root /boot /opt" # Where to backup to. dest="/mnt/backup" # Create archive filename. day=$(date +%A) hostname=$(hostname -s) archive_file="$hostname-$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 #Selesai
Referensi :