This is a compilation of bash scripts that have been used for various needs. It's here for reference and as an archive.
DokuWiki NameSpace Export
#!/bin/bash -vx #This script is for extracting all sub-namespaces under a specified namespace in Dokuwiki. #Each sub-namespace directly after the specified namespace is copied as a seperate namespace from all other sub-namespaces. #The associated pages and media folders are copied then combined with DokuWikiStick then compressed and encrypted. #Finally they are copied to a remote server via SSH. #All file operations are run in tmpfs mount point which is removed at the end of the script #Variables for Dokuwiki root paths where sub name-spaces will be backed up #Pages Path (include trailing / in path) root_pages_path="/var/www/html/dataserver.server.com/dokuwiki-data/data/pages/server_data/" #Corresponding Media Path (include trailing / in path) root_media_path="/var/www/html/dataserver.server.com/dokuwiki-data/data/media/server_data/" #Destination Backup Path backup_destination="/var/www/html/dataserver.server.com/dokuwiki-data/backup_tmpfs" #TMPFS where data will be copied to before archiving/encrypting backup_tmpfs="/var/www/html/dataserver.server.com/dokuwiki-data/backup_tmpfs" #Dokuwikistick Template Source Path dokuwikistick_template="/var/www/html/dataserver.server.com/dokuwiki-data/dokuwikistick_template" #Dokuwikistick Data Destination Path dokuwikistick_destination="DokuWikiStick/dokuwiki/data" #Dokuwikistick Pages/Media Variable stick_pages="pages/server_data" stick_media="media/server_data" #SSH key for copying to remote host ssh_key="/root/.ssh/root@dataserver.server.com-user@ht-sync01" #SSH remote user@host ssh_remote_user="user@remote.ip.addr.ess" #SSH remote backup path ssh_remote_backup="/home/user/xfer/server_data_backups" #End of Variables #Check if path exists for tmpfs mount point, create it if if doesn't exist if [[ ! -d ${backup_tmpfs} ]]; then mkdir -p ${backup_tmpfs} fi #Mount tmpfs filesystem mount -t tmpfs -o size=100m,mode=700 tmpfs $backup_tmpfs #Create backup of pages and media paths for each client folder where d represents the folder below server_data for d in $root_pages_path*/ ; do d=${d#"$root_pages_path"} echo "$d" if [[ ! -d ${backup_tmpfs}/${d} ]]; then mkdir -p ${backup_tmpfs}/${d}/${dokuwikistick_destination}/${stick_pages}/${d} mkdir -p ${backup_tmpfs}/${d}/${dokuwikistick_destination}/${stick_media}/${d} fi if [[ -d $root_pages_path/${d} ]]; then rsync -av ${root_pages_path}/${d} ${backup_tmpfs}/${d}/${dokuwikistick_destination}/${stick_pages}/${d} fi if [[ -d $root_media_path/${d} ]]; then rsync -av ${root_media_path}/${d} ${backup_tmpfs}/${d}/${dokuwikistick_destination}/${stick_media}/${d} fi rsync -av $dokuwikistick_template/ ${backup_tmpfs}/${d}/DokuWikiStick/ #Remove trailing slash from $d d=${d%/} 7za a -r -mx=1 -pPassWordGoesHere $backup_destination/"$d"_encrypted.7z ${backup_tmpfs}/${d}/DokuWikiStick/ #Copy to remote host scp -i ${ssh_key} $backup_destination/"$d"_encrypted.7z ${ssh_remote_user}:${ssh_remote_backup}/"$d"_encrypted.7z #Remove all data from the backup tmpfs path rm -rf ${backup_tmpfs}/* done #Unmount the backup tmpfs after all is done sleep 5 umount ${backup_tmpfs}
Rsync over SSH
#!/bin/bash -vx #This is copying the data exports from HT-SYNC01 to Backups directory in local home dir. #It checks if the remote host is accessible before attempting the backup #Rsync over SSH with keys is used if ping -c 1 -W 1 "10.49.0.35"; then echo "HT-SYNC01 is accessible" rsync -Pav -e "ssh -i ~/.ssh/user@localcomputer-remoteuser@remotecomputer" remoteuser@10.49.0.35:~/xfer/data/ ~/Backups/HT-SYNC01/data/ else echo "HT-SYNC01 is NOT accessible" fi