Site icon Learning & Doing

Backup dari Debian/Ubuntu/Centos/Open BSD ke Synology

–Backup dari Debian/Ubuntu ke Synology

apt-get install ftp-upload

mkdir /usr/src/backup/

nano /usr/src/backup.sh

chmod a+x /usr/src/backup.sh

isi file :

#!/bin/bash

export LC_ALL=”en_US.utf8″

cd /etc/dnsdist/
tar -czf /usr/src/backup/dnsdist-$(date +%d%m%Y).tar.gz *
sleep 1m
ftp-upload -h lapo.games.com:221 -u server –password kucing123 -d /Provisioning/Server/DNS/ /usr/src/backup/*$(date +%d%m%Y).tar.gz

find /usr/src/backup/dnsdist-* -mtime +7 -exec rm {} \;

KET : -lapo.games.com:221 -> server nya ; kucing123 -> password ; /etc/dnsdist/ -> file yg mau di backup

Buat Cron nya :

@daily /usr/src/backup.sh

 

–Dari Open BSD / Centos ke Synology

mkdir /home/backup/

nano /home/backup/backup.sh

chmod a+x /home/backup/backup.sh

Isi File :

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

# What to backup.
backup_files1=”/var/named/etc/*”
backup_files2=”/var/named/master/*”

# Where to backup to.
dest=”/home/backup”

# Create archive filename.
day=$(date +”%m-%d-%y”)
#hostname=$(hostname -s)
hostname=’111.68.124.150′
archive_file=”$hostname-$day.tar.gz”

# Print start status message.
echo “Backing up $backup_files1 to $dest/$archive_file”
echo “Backing up $backup_files2 to $dest/$archive_file”
date
echo

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

# Print end status message.
echo
echo “Backup finished”
date

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

# delete file
# find /home/backup/ns1-* -mtime +7 -exec rm {} \;
# sleep 5

# delete file
find /home/backup/111.68.124.150-* -mtime +7 -exec rm {} \;
sleep 5

# log
[ $? -ne 0 ] && echo -e ‘backup \e[91mfailed\e[0m’ >> /var/log/backup/backup.log || echo -e ‘backup \e[32msuccess\e[0m’ >> /var/log/backup/backup.log
#

Buat Cron :

30 1 * * * /bin/sh /home/backup/backup.sh

-Untuk Upload ke Synology di butuhkan 1 server misal debian / ubuntu yang bisa pake ftp-upload

mkdir /usr/local/scripts/

mkidr /home/backup/server/dns/

nano /usr/local/scripts/backup-dns

chmod a+x /usr/local/scripts/backup-dns

Isi File :

#!/bin/bash

#d=$(date ‘+%F’)
d=$(date +”%m-%d-%y”)
pass=”megaminxgames”

echo -e ‘\n[ ‘$d’ ]’ >> /var/log/backup/server-dns.log

#DNS
sshpass -p $pass ssh -p2225 -o StrictHostKeyChecking=no -o ConnectTimeout=10 root@111.68.105.107 stat /home/backup/*$d* > /dev/null 2>&1
[ $? -eq 0 ] && sshpass -p $pass scp -P2225 -o StrictHostKeyChecking=no -o ConnectTimeout=10 root@111.68.105.107 :/home/backup/*$d* /home/backup/server/dns/. || e$

sleep 3m

ftp-upload -h lapo.varnion.com:221 -u server –password 1Bo38xPE8@An -d /Provisioning/Server/DNS/111.68.105.107 /home/backup/server/dns/111.68.105.107 -$d* > /dev/null

[ $? -ne 0 ] && echo -e ‘ftp 111.68.105.107 \e[91mfailed\e[0m’ >> /var/log/backup/server-dns.log || echo -e ‘ftp 111.68.105.107 \e[32msuccess\e[0m’ >> /var/log/backup/$

KET : megaminxgames -> pass root 111.68.105.107 ; /home/backup/*$d*  ->  lokasi file backup

 

Buat Cron :

30 4 * * * /usr/local/scripts/backup-dns > /tmp/backup-dns 2>&1

 

 

Exit mobile version