|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "bash-backup" |
| 4 | +description: "Simple backup shell script by bash v4.*" |
| 5 | +category: utility |
| 6 | +tags: [backup, s3] |
| 7 | +--- |
| 8 | + |
| 9 | +## Usage |
| 10 | +``` |
| 11 | +$ git clone [email protected]:newsdict/bash-backup.git |
| 12 | +$ cd bash-backup |
| 13 | +$ cp env-example .env |
| 14 | +``` |
| 15 | + edit `.env` file |
| 16 | +``` |
| 17 | +$ bash backup.sh [--debug] |
| 18 | +``` |
| 19 | +### Multiple Targets |
| 20 | +``` |
| 21 | +$ git clone [email protected]:newsdict/bash-backup.git |
| 22 | +$ cd bash-backup |
| 23 | +$ cp env-example .env-sample1 |
| 24 | +``` |
| 25 | +edit `.env-sample1` file |
| 26 | +``` |
| 27 | +$ cp env-example .env-sample2 |
| 28 | +``` |
| 29 | +edit `.env-sample2` file |
| 30 | +``` |
| 31 | +$ sh backup.sh [--debug] sample1 |
| 32 | +$ sh backup.sh [--debug] sample2 |
| 33 | +``` |
| 34 | +## Flow |
| 35 | + |
| 36 | +1. Archive the datas. (tar.gz or tar.bz2 or zip) |
| 37 | +2. mysqldump - only mysql yet.... |
| 38 | +3. Rearchive the 1 and 2 (tar.gz or tar.bz2 or zip) |
| 39 | +4. Upload to S3. (Generation management) - only s3 yet....... |
| 40 | + |
| 41 | +## Environments |
| 42 | + |
| 43 | +### Temporary Directory |
| 44 | +``` |
| 45 | +temporary_directory=tmp |
| 46 | +``` |
| 47 | + |
| 48 | +### log name |
| 49 | +``` |
| 50 | +log_name=logs/backup.$now.log |
| 51 | +``` |
| 52 | + |
| 53 | +### backup filename |
| 54 | +``` |
| 55 | +backup_filename=backup |
| 56 | +``` |
| 57 | + |
| 58 | +### display messages |
| 59 | +``` |
| 60 | +display_messages=1 |
| 61 | +``` |
| 62 | + |
| 63 | +### Execute archive |
| 64 | +``` |
| 65 | +archive=1 |
| 66 | +``` |
| 67 | + |
| 68 | +### Archive paths or files |
| 69 | +``` |
| 70 | +declare -a archive_paths=( |
| 71 | + "/var/www/html" |
| 72 | + "/etc/nginx" |
| 73 | +) |
| 74 | +``` |
| 75 | + |
| 76 | + |
| 77 | +### Compression type of backup |
| 78 | +``` |
| 79 | +commpression_type=gzip |
| 80 | +``` |
| 81 | +*_gzip: *.tar.gz_ |
| 82 | +*_zip: *.zip_ |
| 83 | +*_bzip2: *.tar.bz2_ |
| 84 | + |
| 85 | +### Execute database |
| 86 | +``` |
| 87 | +database=1 |
| 88 | +``` |
| 89 | + |
| 90 | +### Database Type for Dump |
| 91 | +``` |
| 92 | +declare -A database_conf=( |
| 93 | + ["engine"]="mysql" # mysql only |
| 94 | + ["name"]="sample1_database" # database name |
| 95 | + ["username"]="user1" # username |
| 96 | + ["password"]="pass" # password |
| 97 | + ["host"]="127.0.0.1" # host |
| 98 | + ["port"]=3306 # port |
| 99 | +) |
| 100 | +``` |
| 101 | + |
| 102 | +### Storage type for backup files |
| 103 | +``` |
| 104 | +storage_type=s3 |
| 105 | +``` |
| 106 | + |
| 107 | +*_`s3` only_ |
| 108 | + |
| 109 | +### s3 info |
| 110 | +``` |
| 111 | +declare -A s3_conf=( |
| 112 | + ["keep"]=5 |
| 113 | + ["access_key"]="" |
| 114 | + ["secret"]="" |
| 115 | + ["bucket"]="backup" |
| 116 | + ["path"]="test" |
| 117 | + ["region"]="ap-northeast-1" |
| 118 | +) |
| 119 | +``` |
| 120 | + |
| 121 | +## Links |
| 122 | +* [Source Code (GitHub)][https://github.com/newsdict/bash-backup] |
| 123 | +* [Author: yubele](https://newsdict.xyz) |
0 commit comments