Send Stderr to dev/null but if no error occurs, continue on

给你一囗甜甜゛ 提交于 2019-12-06 05:54:34

Why not splitting ? Something like this:

#!/bin/sh

# Create the backup name
BACKUP_NAME="/tmp/backup-$(date +%Y-%m-%d_%H.%M.%S).sql"

# Run mysqldump and create a raw backup
mysqldump --opt --user=root --password=root --host=localhost --all-databases 2>/dev/null >"${BACKUP_NAME}"

# If no errors, create the gzip backup
test $? = 0 && gzip -c9 "${BACKUP_NAME}" > "${BACKUP_NAME}.gz"

# In any cases remove raw backup
rm -f "${BACKUP_NAME}"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!