#!/bin/sh
BackupPath="/root/upfOps/te"
if [ ! -d "$BackupPath" ]; then
mkdir -p "$BackupPath"
fi
MYSC_JSON_YAML_DB="home/mysc/cmin02sms/etc/{*.json,*.yaml,*.db}"
tar vczf /root/upfOps/te/t1.tar.gz $MYSC_JSON_YAML_DB
echo $MYSC_JSON_YAML_DB
tar vczf /root/upfOps/te/t2.tar.gz /home/mysc/cmin02sms/etc/{*.json,*.yaml,*.db}
Output:
[root@upf-100.novalocal upfOps]# ./test
tar: home/mysc/cmin02sms/etc/{*.json,*.yaml,*.db}:无法 stat: 没有那个文件或目录
tar: 由于前次错误,将以上次的错误状态退出
home/mysc/cmin02sms/etc/{*.json,*.yaml,*.db}
tar: 从成员名中删除开头的“/”
/home/mysc/cmin02sms/etc/conf.ismpbus.json
/home/mysc/cmin02sms/etc/conf.simu.json
/home/mysc/cmin02sms/etc/conf.slrun.json
/home/mysc/cmin02sms/etc/conf.smp.json
/home/mysc/cmin02sms/etc/chassis.yaml
/home/mysc/cmin02sms/etc/lager.yaml
/home/mysc/cmin02sms/etc/microservice.yaml
/home/mysc/cmin02sms/etc/conf.crontab.db
[root@upf-100.novalocal upfOps]#
The first tar command results in "cannot stat: no such file or directory". But the second tar can compress those files successfully.
How to compress a file with multiple file suffixes in a variable? can someone give a solution in any ways just use the sh or bash scripts?
I want use only one variable such as
tempPath=home/mysc/cmin02sms/etc/{*.json,*.yaml,*.db}
tar cvzf /root/etcFiles.tar.gz $tempPath
what is the right ways to write the tempPath variable?