bash script code help to make zip/tar of several folders bash script code help to make zip/tar of several folders bash bash

bash script code help to make zip/tar of several folders


# tar: (c)reate g(z)ip (v)erbose (f)ile [filename.tar.gz] [contents]...tar -czvf /var/file/bkup.tar.gz /home/code/bots /var/config /var/system# zip: (r)ecursive [filename.zip] [contents]...zip -r /var/file/bkup.zip /home/code/bots /var/config /var/system


The problem as you've described it doesn't require a bash script, just tar.

tar cvzf /var/file/bkup.tar.gz /home/code/bots/ /var/config/ . . . /var/system/


You could create a bash file for it, if you intend to run it in a cronjob for example and add some other commands like a mysqldump beforehand

You need to create a file like backup.sh with the following contents(You may need to alter the path to bash, you can find bash with whereis bash)

#!/bin/bash# # Backup script# # Format: YEAR MONTH DAY - HOUR MINUTE SECONDDATE=$(date +%Y%m%d-%H%M%S)# MySQL backup fileMYSQLTARGET="/var/file/backup-mysql-$DATE.sql"# Target fileTARTARGET="/var/file/backup-$DATE.tar.gz"# MySQL dump# you cannot have a space between the option and the password. If you omit the password value # following the --password or -p option on the command line, you are prompted for one.mysqldump -u root -ppassword --all-databases > $MYSQLTARGETtar -czvf $TARTARGET $MYSQLTARGET /home/code/bots /var/config /var/system

PS. This is untested code. It's just an example of how a bash script works in the current replied context.