#!/bin/bash #################################################################################################### #### author: SlickStack ############################################################################ #### link: https://slickstack.io ################################################################### #### mirror: https://mirrors.slickstack.io/bash/ss-dump-files.txt ################################## #### path: /var/www/ss-dump-files ################################################################## #### destination: n/a (not a boilerplate) ########################################################## #### purpose: Dumps html files to /var/www/backups/html/production.tar.gz (SFTP can access) ######## #### module version: Ubuntu 22.04 LTS ############################################################## #### sourced by: n/a ############################################################################### #### bash aliases: ss dump files|html, ss export files|html ######################################## #################################################################################################### ## source ss-config ## source /var/www/ss-config ## source ss-functions ## source /var/www/ss-functions ## BELOW THIS RELIES ON SS-CONFIG AND SS-FUNCTIONS #################################################################################################### #### TABLE OF CONTENTS (SS-Dump-Files) ############################################################# #################################################################################################### ## this is a brief summary of the different code snippets you will find in this script ## ## each section should be commented so you understand what is being accomplished ## ## A. Touch Timestamp File ## B. Message (Begin Script) ## C. Dump Public HTML Directory ## D. Reset Permissions (HTML Dump Files) #################################################################################################### #### A. SS-Dump-Files: Touch Timestamp File ######################################################## #################################################################################################### ## this is a dummy timestamp file that will remember the last time this script was run ## ## it can be useful for developer reference and is sometimes used by SlickStack ## ss_touch "${TIMESTAMP_SS_DUMP_FILES}" #################################################################################################### #### B. SS-Dump-Files: Message (Begin Script) ###################################################### #################################################################################################### ## this is a simple message that announces to the shell the purpose of this bash script ## ## it will only be seen by sudo users who manually run this script in the shell ## ss_echo "${COLOR_INFO}Running ss-dump-files... ${COLOR_RESET}" #################################################################################################### #### C. SS-Dump-Files: Dump Public HTML Directory ################################################## #################################################################################################### ## NEEDED: calculate free space and if free space is less than used space display error and exit ## this is to avoid exhausting disk space and crashing the server ## if free space is okay then dump TAR ball of /html/ to /var/www/backups/html/export.tar.gz (must overwrite each time to save space) ## production ## ss_targz "${PATH_DUMP_FILES_PRODUCTION}" --exclude="staging" --exclude="dev" -C /var/www/html . ## ending period required ## staging ## if [[ "${STAGING_SITE}" == "true" ]]; then ss_targz "${PATH_DUMP_FILES_STAGING}" -C /var/www/html/staging . ## ending period required fi ## development ## if [[ "${DEV_SITE}" == "true" ]]; then ss_targz "${PATH_DUMP_FILES_DEVELOPMENT}" -C /var/www/html/dev . ## ending period required fi #################################################################################################### #### D. SS-Dump-Files: Reset Permissions (HTML Dump Files) ######################################### #################################################################################################### ## here we do a quick permissions reset to ensure SFTP users can access the dump file ## ## keep in mind that root/sudo users will have access to this file regardless ## ## production ## chown -R "${SFTP_USER}":www-data "${PATH_DUMP_FILES_PRODUCTION}" chmod 0440 "${PATH_DUMP_FILES_PRODUCTION}" ## staging ## if [[ "${STAGING_SITE}" == "true" ]]; then chown -R "${SFTP_USER}":www-data "${PATH_DUMP_FILES_STAGING}" chmod 0440 "${PATH_DUMP_FILES_STAGING}" fi ## development ## if [[ "${DEV_SITE}" == "true" ]]; then chown -R "${SFTP_USER}":www-data "${PATH_DUMP_FILES_DEVELOPMENT}" chmod 0440 "${PATH_DUMP_FILES_DEVELOPMENT}" fi #################################################################################################### #### SlickStack: Reset Permissions (SlickStack Scripts) ############################################ #################################################################################################### ## we include this permissions reset in all cron jobs and bash scripts for redundancy ## ## chmod 0700 means only the root/sudo users can execute any SlickStack scripts ## ## THIS SNIPPET DOES NOT RELY ON SS-CONFIG OR SS-FUNCTIONS ## SNIPPET: ss bash scripts, ss cron jobs ## UPDATED: 02JUL2022 chown root:root /var/www/ss* ## must be root:root chown root:root /var/www/crons/*cron* ## must be root:root chown root:root /var/www/crons/custom/*cron* ## must be root:root chmod 0700 /var/www/ss* ## 0700 means only root/sudo can execute chmod 0700 /var/www/crons/*cron* ## 0700 means only root/sudo can execute chmod 0700 /var/www/crons/custom/*cron* ## 0700 means only root/sudo can execute #################################################################################################### #### SlickStack: External References Used To Improve This Script (Thanks, Interwebz) ############### #################################################################################################### ## Ref: https://www.cyberciti.biz/faq/how-do-i-compress-a-whole-linux-or-unix-directory/ ## Ref: https://stackoverflow.com/questions/984204/shell-command-to-tar-directory-excluding-certain-files-folders ## Ref: https://stackoverflow.com/questions/20841727/exclude-directory-while-using-tar ## Ref: https://stackoverflow.com/questions/13341702/how-do-i-turn-off-the-output-from-tar-commands-on-unix ## Ref: https://unix.stackexchange.com/questions/59243/tar-removing-leading-from-member-names/59244 ## Ref: https://askubuntu.com/questions/811081/how-do-i-use-tar-to-exclude-all-files-of-a-certain-directory ## Ref: https://www.computerhope.com/unix/utar.htm ## Ref: https://stackoverflow.com/questions/18681595/tar-a-directory-but-dont-store-full-absolute-paths-in-the-archive ## Ref: https://unix.stackexchange.com/questions/627540/tar-gz-a-directory-in-another-location-into-a-destination-directory ## Ref: https://stackoverflow.com/questions/939982/how-do-i-tar-a-directory-of-files-and-folders-without-including-the-directory-it ## SS_EOF