您可以从 linux bash 终端列出 MongoDB 中的所有数据库吗?我找不到正确的命令。我正在尝试列出所有内容,以便我可以编写一个 bash 脚本来单独备份所有数据库。有没有更好的办法?
主页
/
user-108133
eekfonky's questions
eekfonky
Asked:
2017-10-13 00:22:11 +0800 CST
继承了一个MongoDB,root密码没人知道。有没有办法改变它?我在跑步MongoDB shell version: 3.2.17
。
我想备份数据库,但首先需要访问权限以查看那里有什么
eekfonky
Asked:
2016-10-16 05:47:15 +0800 CST
在一些 MySQL 数据库上,我先备份了它们;
mysql_config_editor set -h localhost -G dbbkup -P 3306 -u root -p
然后运行一个小脚本;
#!/bin/bash
BACKUPDIR="/home/deploy/backup-db"
BKUPSSH="[email protected]"
BKUPSERVDIR="/home/deploy/backups/databases"
# Remove files older than 30 days
find $BACKUPDIR/ -mtime +31 -exec rm {} \;
# DO NOT BACKUP these databases
IGNOREDB="
information_schema
mysql
test"
#* MySQL binaries *#
MYSQL=$(which mysql)
MYSQLDUMP=$(which mysqldump)
GZIP=$(which gzip)
# assuming that BACKUPDIR exists
if [ ! -d $BACKUPDIR ]; then
mkdir -p $BACKUPDIR
else
:
fi
# get all database listing
DBS="$(mysql --login-path=dbbkup -Bse 'show databases')"
# Set date and time for the file
NOW=$(date +"%Y-%m-%d_%H.%M"); # year-month-day_hour.minute format
# start to dump database one by one
for db in $DBS
do
DUMP="yes";
if [ "$IGNOREDB" != "" ]; then
for i in $IGNOREDB # Store all value of $IGNOREDB ON i
do
if [ "$db" == "$i" ]; then # If result of $DBS(db) is equal to $IGNOREDB(i) then
DUMP="NO"; # SET value of DUMP to "no"
#echo "$i database is being ignored!";
fi
done
fi
if [ "$DUMP" == "yes" ]; then # If value of DUMP is "yes" then backup database
FILE="$BACKUPDIR/$NOW-$db.sql.gz";
echo "BACKING UP $db";
$MYSQLDUMP --login-path=dbbkup --add-drop-database --opt --lock-all-tables --set-gtid-purged=OFF $db | $GZIP > $FILE
fi
done
# change permissions on files
chmod -R 755 $BACKUPDIR
# rsync backup to 'Larry' the backup server and append the log file
rsync -azv $BACKUPDIR -e ssh $BKUPSSH:$BKUPSERVDIR >> /home/deploy/db_rsync.log 2>&1
RESULT="$?"
# check result of rsync
if [ "$RESULT" != "0" ]; then
echo -e "rsync exit Code:" $RESULT "\nFailed to rsync databases" >> /home/deploy/db_rsync.log 2>&1
else
echo "succesfully rsynced databases" >> /home/deploy/db_rsync.log 2>&1
fi
由于我不是交易的 DBA,有谁知道我如何通过稍微调整用于 PostgreSQL 的脚本来实现同样的目标?