for
Bash,psql,当使用循环将更多 pgdump 文件恢复到更多数据库时如何使用通配符?
例子。
postgres@usl-ecdt1-t:~$ cat db
coopzilinask_shop
coopzilinask_web
ggtabakcz_shop
kitoscz_shop
kitossk_shop
metroua_shop
unihobbycz_shop
unihobbycz_web
utccz_shop
vinotekacz_shop
要导入的文件的格式,末尾带有日期。
postgres@usl-ecdt1-t:~$ ls -la /var/www/html/coopzilinask/dbdump/coopzilinask-shop-20200219094001.pgsql
-rw-r--r-- 1 shosek ecommerce 871261032 Feb 19 09:43 /var/www/html/coopzilinask/dbdump/coopzilinask-shop-20200219094001.pgsql
postgres@usl-ecdt1-t:~$
在数据库中恢复的命令。
postgres@usl-ecdt1-t:~$ for i in $(cat db | grep -v "#"); do psql -U postgres -d "$i"_clone -1 -f /var/www/html/"$i"/dbdump/$i*.pgdump; done
但它向我展示了这一点。
postgres@usl-ecdt1-t:~$ for i in $(cat db | grep -v "#"); do psql -U postgres -d "$i"_clone -1 -f /var/www/html/"$i"/dbdump/$i*.pgdump; done
/var/www/html/coopzilinask_shop/dbdump/coopzilinask_shop*.pgdump: No such file or directory
/var/www/html/coopzilinask_web/dbdump/coopzilinask_web*.pgdump: No such file or directory
/var/www/html/ggtabakcz_shop/dbdump/ggtabakcz_shop*.pgdump: No such file or directory
/var/www/html/kitoscz_shop/dbdump/kitoscz_shop*.pgdump: No such file or directory
/var/www/html/kitossk_shop/dbdump/kitossk_shop*.pgdump: No such file or directory
/var/www/html/metroua_shop/dbdump/metroua_shop*.pgdump: No such file or directory
/var/www/html/unihobbycz_shop/dbdump/unihobbycz_shop*.pgdump: No such file or directory
/var/www/html/unihobbycz_web/dbdump/unihobbycz_web*.pgdump: No such file or directory
/var/www/html/utccz_shop/dbdump/utccz_shop*.pgdump: No such file or directory
/var/www/html/vinotekacz_shop/dbdump/vinotekacz_shop*.pgdump: No such file or directory
postgres@usl-ecdt1-t:~$
通配符错误。我怎样才能在名称后面而不是日期后面应用通配符?谢谢。
答案1
您的文件确实以后缀结尾.pgsql
不是 .pgdump
:
/var/www/html/coopzilinask/dbdump/coopzilinask-shop-20200219094001。数据库查询语言
重命名文件或尝试此命令:
for i in $(cat db | grep -v "#"); do psql -U postgres -d "$i"_clone -1 -f /var/www/html/"$i"/dbdump/$i*.pgsql; done