报送举报网站建设情况,wordpress自动采集图片,网络营销做得比较成功的案例,口碑营销中容易出现哪些问题数据安全是做数据分析的人需要关注的一大问题。对于我们分析的关键数据、使用的关键脚本都需要定期备份。scp最简单的备份方式#xff0c;就是使用cp (本地硬盘)或scp (远程硬盘)命令#xff0c;给自己的结果文件新建一个拷贝;每有更新#xff0c;再拷贝一份。具体命令如下就是使用cp (本地硬盘)或scp (远程硬盘)命令给自己的结果文件新建一个拷贝;每有更新再拷贝一份。具体命令如下cp -fur source_project project_bakscp -r source_project userremote_server_ip:project_bak为了实现定期备份我们可以把上述命令写入crontab程序中设置每天的晚上23:00执行。对于远程服务器的备份我们可以配置免密码登录便于自动备份。后台输入免密码登录服务器获取免密码登录服务器的方法。# Crontab format# MinuteHourDayMonthWeekcommand# * 表示每分/时/天/月/周# 每天23:00 执行cp命令0 23 * * * cp -fur source_project project_bak# */2 表示每隔2分分/时/天/月/周执行命令# 每隔24小时执行cp命令0 */24 * * * cp -fur source_project project_bak0 0 */1 * * scp -r source_project userremote_server_ip:project_bak# 另外crotab还有个特殊的时间# reboot: 开机运行指定命令reboot cmdrsynccp或scp使用简单但每次执行都会对所有文件进行拷贝耗时耗力尤其是需要拷贝的内容很多时重复拷贝对时间和硬盘都是个损耗。rsync则是一个增量备份工具只针对修改过的文件的修改过的部分进行同步备份大大缩短了传输的文件的数量和传输时间。具体使用如下 # 把本地project目录下的东西备份到远程服务器的/backup/project目录下# 注意***个project后面的反斜线表示拷贝目录内的内容不在目标目录新建project文件夹。注意与第二个命令的比较两者实现同样的功能。# -a: archive mode, quals -rlptgoD# -r: 递归同步# -p: 同步时保留原文件的权限设置# -u: 若文件在远端做过更新则不同步避免覆盖远端的修改# -L: 同步符号链接链接的文件防止在远程服务器出现文件路径等不匹配导致的软连接失效# -t: 保留修改时间# -v: 显示更新信息# -z: 传输过程中压缩文件对于传输速度慢时适用rsync -aruLptvz --delete project/ userremoteServer:/backup/projectrsync -aruLptvz --delete project userremoteServer:/backup/rsync所做的工作为镜像保证远端服务器与本地文件的统一。如果本地文件没问题远端也不会有问题。但如果发生误删或因程序运行错误导致文件出问题而在同步之前又没有意识到的话远端的备份也就没了备份的意义因为它也被损坏了。误删是比较容易发现的可以及时矫正。但程序运行出问题则不一定了。rdiff-backup这里推荐一个工具rdiff-backup不只可以做增量备份而且会保留每次备份的状态新备份和上一次备份的差别可以轻松回到之前的某个版本。***的要求就是本地服务器和远端服务器需要安装统一版本的rdiff-backup。另外还有2款工具 duplicity和Rsnapshot也可以做类似工作但方法不一样占用的磁盘空间也不一样具体可查看原文链接中的比较。具体的rdiff-backup安装和使用如下 (之前写的是英文内容比较简单就不再翻译了)Install rdiff-backup at both local and remote computers#installforubuntu, debiansudo apt-get install python-dev librsync-dev#self compile#downlaod rsync-dev fromhttps://sourceforge.net/project/showfiles.php?group_id56125tar xvzf librsync-0.9.7.tar.gzexport CFLAGS$CFLAGS -fPIC./configure --prefix/home/user/rsync --with-picmakemake installInstall rdiff-backup#See Reference partfordownload link# http://www.nongnu.org/rdiff-backup/python setup.py install --prefix/home/user/rdiff-backup#If you complied rsync-dev yourself, please specify the location ofrsync-devpython setup.py --librsync-dir/home/user/rsync install -- prefix/home/user/rdiff-backupAdd exeutable files and python modules to environmental variables#Addthe following wordsinto.bashrcor.bash_profileoranyother config filesexport PATH${PATH}:/home/user/rdiff-backup/binexport PYTHONPATH${PYTHONPATH}:/home/user/rdiff-backup/lib/python2.x/site-packages#pay attention tothe xinpython2.xofabove line which can be 6or7 dependingon#the Python version used.Test environmental variable when executing commands through sshsshuserhostecho ${PATH}#WhenI run this commandinmylocalcomputer,#I found onlysystem environmetal variableisused#andnoneofmy self-defined environmetal variableisused.#Then, I modified the following linesinfileSetConnections.pyin#/home/user/rdiff-backup/lib/python2.x/site-packages/rdiff_backup#tosetenvironmental explicitlywhenlogin.#pay attention tothe single quote used insidedoublequote__cmd_schema ssh -C %s source ~/.bash_profile; rdiff-backup --server__cmd_schema_no_compress ssh %s source ~/.bash_profile; rdiff-backup --server#choose the one containsenvironmental variableforrdiff-backupfrom.bash_profileand.bashrc.Use rdiff-backupStart backuprdiff-backup --no-compression --print-statistics userhost::/home/user/source_dir destination_dirIf the destination_dir exists, please add --force like rdiff-backup --no-compression --force --print-statistics userhost::/home/user/source_dir destination_dir. All things in original destination_dir will be depleted.If you want to exclude or include special files or dirs please specify like --exclude **trash or --include /home/user/source_dir/important.Timely backup your dataAdd the above command into crontab (hit crontab -e in terminal to open crontab) in the format like 5 22 */1 * * command which means executing the command at 22:05 everyday.Restore dataRestore the latest data by running rdiff-backup -r now destination_dir userhost::/home/user/source_dir.restore. Add --force if you want to restore to source_dir.Restore files 10 days ago by running rdiff-backup -r 10D destination_dir userhost::/home/user/source_dir.restore. Other acceptable time formats include 5m4s (5 minutes 4 seconds) and 2014-01-01 (January 1st, 2014).Restore files from an increment file by running rdiff-backup destination_dir/rdiff-backup-data/increments/server_add.2014-02-21T09:22:4508:00.missing userhost::/home/user/source_dir.restore/server_add. Increment files are stored in destination_dir/rdiff-backup-data/increments/server_add.2014-02-21T09:22:4508:00.missing.Remove older records to save spaceDeletes all information concerning file versions which have not been current for 2 weeks by running rdiff-backup --remove-older-than 2W --force destination_dir. Note that an existing file which has not changed for a year will still be preserved. But a file which was deleted 15 days ago can not be restored after this command. Normally one should use --force since it is used to delete multiple increments at the same time which --remove-older-thanrefuses to do by default.Only keeps the last n rdiff-backup sessions by running rdiff-backup --remove-older-than 20B --force destination_dir.StatisticsLists increments in given golder by rdiff-backup --list-increments destination_dir/.Lists of files changed in last 5 days by rdiff-backup --list-changed-since 5D destination_dir/.Compare the difference between source and bak by rdiff-backup --compare userhost::source-dir destination_dirCompare the sifference between source and bak (as it was two weeks ago) by rdiff-backup --compare-at-time 2W userhost::source-dir destination_dir.A complete script (automatically sync using crontab)#!/bin/bashexport PYTHONPATH${PYTHONPATH}:/soft/rdiff_backup/lib/python2.7/site-packages/rdiff-backup --no-compression -v5 --exclude **trash userserver::source/ bak_dir/ret$?if test $ret -ne 0; thenecho Wrong in bak| mutt -sWrong in bakbakmail.comelseecho Right in bak| mutt -sRight in bakbakmail.comfiecho Finish rdiff-backup $0 ---date---bak.log 21echo rdiff-backup --exclude **trash --compare-at-time 1D userserver::source/ bak_dir/| mutt -sLists of baked filesbakmail.comReferencesrdiff-backupduplicityrsnapshothttp://www.saltycrane.com/blog/2008/02/backup-on-linux-rsnapshot-vs-rdiff/http://james.lab6.com/2008/07/09/rdiff-backup-and-duplicity/http://bitflop.com/document/75http://askubuntu.com/questions/2596/comparison-of-backup-toolshttp://www.reddit.com/r/linux/comments/fgmbb/rdiffbackup_duplicity_or_rsnapshot_which_is/http://serverfault.com/questions/491341/optimize-space-rdiff-backupAnother great post on usage of rdiff-backup【编辑推荐】【责任编辑武晓燕 TEL(010)68476606】