How Completely Script Backup and Save FTP Server on Linux
Written by vaheeD on January 17, 2013
STEP1: Create a file for backup Script
# vi backup.sh
Paste blow script
### System Setup ### DIRS="/etc/ /var/ " BACKUP=/tmp/backup NOW=$(date +"%d-%m-%Y") INCFILE="/root/tar-inc-backup.dat" DAY=$(date +"%a") FULLBACKUP="Sun" ### FTP server Setup ### FTPD="/" FTPU="usernameFTP" FTPP="passwordFTP" FTPS="IP_FTP_SERVER" NCFTP="$(which ncftpput)" ### Start Backup for file system ### [ ! -d $BACKUP ] && mkdir -p $BACKUP || : ### See if we want to make a full backup ### if [ "$DAY" == "$FULLBACKUP" ]; then FTPD="/" FILE="fs-full-$NOW.tar.gz" tar -zcvf $BACKUP/$FILE $DIRS else i=$(date +"%Hh%Mm%Ss") FILE="fs-i-$NOW-$i.tar.gz" tar -g $INCFILE -zcvf $BACKUP/$FILE $DIRS fi ### Dump backup using FTP ### #Start FTP backup using ncftp ncftp -u"$FTPU" -p"$FTPP" $FTPS<<EOF mkdir $FTPD mkdir $FTPD/$NOW cd $FTPD/$NOW lcd $BACKUP mput * quit EOF
then please save and exit with :wq ( vi editor )
SRETP2: now executable backup script
# chmod u+x backup.sh
OR
# chmod 755 backup.sh
STEP3: please install “ncftp” Package
# apt-get install ncftp
STEP4: now run backup script or put in crontab for automated run AT time
For running backup script:
# sh backup.sh
OR
# ./backup.sh
For Crontab:
# crontab -e #Select vi for edit
Put this line and of file
0 5 * * 1 /root/backup.sh # or path backup.sh file
Save and exit with :wq ( vi editor )
Sample crontab :
Crontab Syntax Chart
1 2 3 4 5 6 7 |
|