diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..eba84eb --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: generic +jobs: + include: + - script: 'shellcheck script.sh' diff --git a/README.MD b/README.MD index 6d95e99..33f11c2 100644 --- a/README.MD +++ b/README.MD @@ -1,31 +1,35 @@ -[Bash]FTP Backup Script -====================== -A small script to upload backup tar to an external FTP server +# [Bash] Backup Script +[![Build Status](https://travis-ci.org/Pe46dro/Bash-FTP-Backup-Script.svg?branch=master)](https://travis-ci.org/Pe46dro/Bash-FTP-Backup-Script) [![Beerpay](https://img.shields.io/beerpay/hashdog/scrapfy-chrome-extension.svg)](https://beerpay.io/Pe46dro/Bash-FTP-Backup-Script) -How it works: -* You need to change "USERNAME,PASSWORD,SERVER" with information of your server -* You need to change "DIR" with absolute position of folder/file you want backup -* You need to change "FILE" with results of compression +A small script to backup a compressed folder to an external storage -If you have some problem open an issues on GitHub - -##FAQ; - -* Q: How can I make backups automatic? +### Prerequisites +Here you find the software that you need to install to have the function working +* cURL (Telegram notifications) +* mailx (Email notifications) +* Rclone (Rclone backup) - A: You can use crontab (on linux) [link](http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/) +## How it works: +* Clone the repository `git clone https://github.com/Pe46dro/Bash-FTP-Backup-Script.git` or download script.sh `wget https://github.com/Pe46dro/Bash-FTP-Backup-Script/blob/master/script.sh` +* Open script.sh with your favorite text editor `vim script.sh` +* Customize the configuration and save +* Run `bash script.sh` +If you have some problem open an issues on GitHub -* Q: Why can't I start the script? +## FAQ - A: Make the file executable (chmod -x script.sh) +* Q: How can I make backups automatic? + A: Yes, you can use [crontab](http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/) + +# Contributors +| [](https://github.com/Pe46dro) | +|--| +| [Pe46dro](https://github.com/Pe46dro) | -* Q: Will this work on all linux distros? - A: This script was tested on Ubuntu 12/14,Debian and Centos 6 and has worked whitout any problems - -* Q: Why SFTP don't work? +## License - A: You need to install "sshpass" ( apt-get install sshpass ) \ No newline at end of file +This project is licensed under the GNU General Public License v3.0 License - see the [LICENSE.md](LICENSE.md) file for details diff --git a/script.sh b/script.sh index 1a9ff4a..7cd0bd5 100644 --- a/script.sh +++ b/script.sh @@ -1,65 +1,273 @@ -#!/bin/sh +#!/usr/bin/env bash -# Linux FTP Backup Script -# Version: 1.0 -# Script by: Pietro Marangon -# Skype: pe46dro -# Email: pietro.marangon@gmail.com +# Linux Simple Backup Script -clean_backup() { - rm -f ./$FILE - echo 'Local Backup Removed' -} +# +# Configuration +# -######################## -# Edit Below This Line # -######################## +# Backup Information +FILE="BACKUP_NAME" #Filename of backup file to be transfered (string) +EXT="zip" #Possbile value: zip,tar (string) +DIR="/var/www" #Directory where thing to backup is located (string) +EXCLUSION=("/var/www/**/node_modules" "/var/www/**/vendor") #Directory to exclude (array space separeted) +CHECKSUM=true #Generate backup checksum (true|false) +ROTATION=30 #How many day keep for better rotation use RClone (int|false) +LOG_FILE="/dev/null" #Log file location (string|/dev/null) +TMP_FOLDER="/tmp/" #Temp folder for archive generation -# FTP Login Data -USERNAME="USERNAME HERE" -PASSWORD="PASSWORD HERE" -SERVER="IP HERE" -PORT="REMOTE SERVER PORT" +#Encryption Information (only zip) +ENCRYPTION=false #Encryption (true|false) +ENCRYPTION_RANDOM=false #Random key generation (true|false) (Require notification enable) +ENCRYPTION_KEY="./my_super_secret_backup.key" #Encryption key (absolute path to file with key) -#Directory where thing to backup is located -DIR="/root" +#Notifications information +NOTIFICATION=false #Notifications (true|false) +SEND_LOG=false #Send log file (true|false) -#Remote directory where the backup will be placed -REMOTEDIR="./" +#Notifications Type +#1= Telegram Bot +#2= FUTURE USE +NOTIFICATION_TYPE=(1) #Multiple notifications support (array space separeted) -#Filename of backup file to be transfered DON'T WRITE EXTENSION (.tar/.zip/ecc...) -FILE="BACKUP_NAME" +TELEGRAM_KEY="YOUR_TELEGRAM_BOT_KEY" #Multiple notifications support (string) +TELEGRAM_CHAT=(1) #Multiple recipient support (array space separeted) #Transfer type #1=FTP -#2=SFTP -TYPE=1 +#2=Rclone https://rclone.org/ +TYPE=(1 2) #Multiple destinations support (array space separeted) -############################## -# Don't Edit Below This Line # -############################## +# FTP(s) Login Data +USERNAME="USERNAME HERE" #Login username (string) +PASSWORD="PASSWORD HERE" #Login password (string) +SERVER="IP HERE" #Remote server address (string) +PORT="REMOTE SERVER PORT" #Remote server port (string) +REMOTEDIR="./" #Remote server port (string) -d=$(date --iso) +# RClone Configuration +RCLONE_PATH="/usr/local/bin" #RClone binary folder (string) +RCLONE_REMOTE=("DEST1:/" "DEST2:/") #Rclone destinations (array space separeted) -FILE=$FILE"_"$d".tar.gz" -tar -czvf ./$FILE $DIR -echo 'Tar Complete' +# Task Configuration +BEFORE_COMMAND=false #Command to run before backup start (string|false) +AFTER_COMMAND=false #Command to run after backup finish (string|false) -if [ $TYPE -eq 1 ] -then -ftp -n -i $SERVER $PORT <