简单的shell脚本备份数据库和代码
2011-06-03 18:13
537 查看
备份数据库
#!/bin/bash
DATE=`date +%Y-%m-%d`
mysqldump --opt dbname -u username -ppassword | gzip > /bakdir/dbbak/test$DATE.gz
#红色标记根据自己的情况进行修改
备份代码
#!/bin/bash
#运行脚本要给用户执行权限
bakdir=/bakdir/picbak
month=`date +%m`
day=`date +%d`
year=`date +%Y`
#dirname=$year-$month-$day-$hour-$min
gzupload=$year-$month-$day
cd /opt/backpic
tar -czf $bakdir/$gzupload-pic.tgz .
----------------------------------------------------------------------------------
tar cannot stat
Wtf? you might reasonably exclaim, unless you’re used to using *nix (Linux, UNIX, etc) from the command line.
tar is a command for moving a file or files into a single archive file (or for reversing the operation). It can also apply compression/decompression algorithms, and perform various other neat tricks. It’s useful and ubiquitous. Unfortunately, it’s also quite sensitive.
Just now, I was using tar -cfz mytarfile.tar.gz mydirectory to archive a directory, and this returned the error, tar: mytarfile.tar.gz: Cannot stat: No such file or directory
tar: Error exit delayed from previous errors. Hmm, not good.
Easy to fix, though. The solution to the problem is this: I should have written, tar -czf mytarfile.tar.gz mydirectory. In other words, the z and the f get swapped in the options. This is because the f option is supposed to denote that what follows it is a file. So the first command I tried was looking for a file called mytarfile.tar.gz to add to an archive file called z. Since the mytarfile.tar.gz didn’t exist, tar couldn’t locate, or stat, the file. Hence the error.
Oh, what fun is to be had at the command line!
本文出自 “Mr. Kang” 博客,请务必保留此出处http://kangyang.blog.51cto.com/471772/580852
#!/bin/bash
DATE=`date +%Y-%m-%d`
mysqldump --opt dbname -u username -ppassword | gzip > /bakdir/dbbak/test$DATE.gz
#红色标记根据自己的情况进行修改
备份代码
#!/bin/bash
#运行脚本要给用户执行权限
bakdir=/bakdir/picbak
month=`date +%m`
day=`date +%d`
year=`date +%Y`
#dirname=$year-$month-$day-$hour-$min
gzupload=$year-$month-$day
cd /opt/backpic
tar -czf $bakdir/$gzupload-pic.tgz .
----------------------------------------------------------------------------------
tar cannot stat
Wtf? you might reasonably exclaim, unless you’re used to using *nix (Linux, UNIX, etc) from the command line.
tar is a command for moving a file or files into a single archive file (or for reversing the operation). It can also apply compression/decompression algorithms, and perform various other neat tricks. It’s useful and ubiquitous. Unfortunately, it’s also quite sensitive.
Just now, I was using tar -cfz mytarfile.tar.gz mydirectory to archive a directory, and this returned the error, tar: mytarfile.tar.gz: Cannot stat: No such file or directory
tar: Error exit delayed from previous errors. Hmm, not good.
Easy to fix, though. The solution to the problem is this: I should have written, tar -czf mytarfile.tar.gz mydirectory. In other words, the z and the f get swapped in the options. This is because the f option is supposed to denote that what follows it is a file. So the first command I tried was looking for a file called mytarfile.tar.gz to add to an archive file called z. Since the mytarfile.tar.gz didn’t exist, tar couldn’t locate, or stat, the file. Hence the error.
Oh, what fun is to be had at the command line!
本文出自 “Mr. Kang” 博客,请务必保留此出处http://kangyang.blog.51cto.com/471772/580852
相关文章推荐
- web服务文件更新自动同步、数据库主从复制、shell脚本实现网站代码备份和mysql备份
- 简单的shell数据库备份脚本
- 简单的远程FTP定时备份Shell脚本分享
- Centos上通过shell脚本实现数据库备份和还原
- shell脚本:完成数据库的自动备份和删除
- 非常简单的shell备份脚本
- 备份shell脚本实例代码
- 简单的SQL Server备份脚本代码
- linux上mysql远程备份和自动导入到指定数据库的shell脚本
- 简单的SQL Server备份脚本代码
- CentOS中使用Shell脚本实现每天自动备份网站文件和数据库并上传到FTP中(转)
- 简单的远程FTP定时备份Shell脚本分享
- 简单的远程FTP定时备份Shell脚本分享
- 简单的远程FTP定时备份Shell脚本分享
- Shell脚本定时备份清除运行系统日志的代码
- 并发数据库压力测试的shell脚本代码
- 简单的数据库备份脚本
- CentOS下编写shell脚本自动备份数据库与网站
- 一个简单的MySQL备份Shell脚本