-3

I am trying to build a really flexible and useful Server Backup Bash Script. I have pretty much no experience working or building Bash scripts.

I know that thousands of them exist in the wild but I want a more customized one that has the most of these features as I can.

So my main question here is, reading my desired feature list... Can you tell me if any of these feature are not possible?

Appreciate any help I am trying to learn this so lots of trial an error. I have 15 years as a web developer, just not any experience with Bash scripts...yet! Thanks for any help!

Will be for Ubuntu.

Backup Features:

- Backup defined Folder of files (folder/filepath set to a variable $FOLDER_NAME_PATH)
- compress files/folder into a .tar archive
- Backup MySQL Database
- compress MYSQL backup file into a .tar archive
- Write all backups to a Log file with the Date and Filepaths of backed up files (
        1/12/2015 - MySQL Database $DATABASE_NAME backed up.
        1/12/2015 - File/Folder $FOLDER_NAME_PATH backed up to 1-12-2015-files.rar.gz
)
- Rotate backup files, deleting files older than 8 days
- Upload the Files and Database Backup archives to a folder OR remote server based on a setting (
        // You can upload to any of these including more then 1 based on setting mentioned below
        - Copy Backup files to another Folder on same server
        - Upload Backup files to remote server using SCP
        - Upload Backup files to remote server using SFTP
        - Upload Backup files to remote server using RSYNC
)
- Email Notification Date & File path's of all backed up files sent to a list of Email Addresses(check for mail OR sendmail)
- Email list of Email addresses on Error
- Make all the above features optional on/off with switch variables! (
        - ON/OFF Backup File/Folder
        - ON/OFF Backup MySQL Database
        - ON/OFF Rotating files.  Deleting older backup files can be turned on or off
        - ON/OFF Write all backup jobs to a Log File
        - ON/OFF Copy backed up files to another Local Folder on same server
        - ON/OFF Upload backup files to SCP Server
        - ON/OFF Upload backup files to SFTP Server
        - ON/OFF Upload backup files to RSYNC Server
        - ON/OFF Email Notifications for successful backup
        - ON/OFF Email Notifications for Errors
)

POSSIBBLE FEATURES - UNCERTAIN IF THEY ARE POSSIBLE OR NOT??

- If Rsync backup is enabled, check to make sure it is installed.  
  If it is not then Install it and then run it?    

- If Email notifications are ON.  Then check that MAIL is working 
 (it's not on my server!)  Then if it is NOT working then check for
  SENDMAIL (SENDMAIL does work on my server!).  Attempt to find one or the other that might be working?  Possible?    

- If SFTP backup is ON.  Check that it is installed.    

- If SCP is ON.  Check that it is installed.    

- When it checks for an installed program and it;s not found or working,  
 is it possible to automatically install the program and then re-run that code?
JasonDavis
  • 2,658
  • 6
  • 25
  • 32

1 Answers1

1

Everything is possible. But - not with pure bash - send e-mail with only bash, not sendmail is not trival ;) The same with sending files. Everything need external programs - bash can only control them.

You must remember, that in various distributions can be different tools installed - for example mail command sometimes can add attachment to mails, sometimes not. The same with installing packages - instalation on centos/redhat is different than in debian/ubuntu. If you're creating this tool only for specific version of ubuntu - this problem is not important.

Handling different distributions, variations of systems - is possible in bash, but - not trival. And - bash is slow, so - doing complrex things will be slow. Sometimes - better create a script, which check environment and dependly on it - install needed packages, and set correct variables/functions for main program.

undefine
  • 1,046
  • 9
  • 21