Skip to content

Instantly share code, notes, and snippets.

@laoshuterry
Created October 31, 2015 09:54
Show Gist options
  • Save laoshuterry/30f1724aa87d8b7b7299 to your computer and use it in GitHub Desktop.
Save laoshuterry/30f1724aa87d8b7b7299 to your computer and use it in GitHub Desktop.
#!/bin/bash
#备份数据库
datetime=$(date +%y%m%d)
size=$(du -sh /home/fatmouse/sh)
if [ -d /home/fatmouse/backup ];then
echo "Date: $datetime">/home/fatmouse/sh/info.txt
echo "Size: $size" >>/home/fatmouse/sh/info.txt
cd /home/fatmouse/backup
tar -zcf Backup_$datetime.tar.gz /home/fatmouse/sh /home/fatmouse/info.txt &> /dev/null
rm -rf /home/fatmouse/sh/info.txt
else
mkdir /home/fatmouse/backup
echo "Date: $datetime">/home/fatmouse/sh/info.txt
echo "Size: $size" >>/home/fatmouse/sh/info.txt
cd /home/fatmouse/backup
tar -zcf Backup_$datetime.tar.gz /home/fatmouse/sh /home/fatmouse/info.txt &> /dev/null
rm -rf /home/fatmouse/sh/info.txt
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment