‘rsync’ command source and destination explained

information sign on paper

rsync command is super useful because it could incrementally sync files between locations without the overhead of compressing and transferring. There are heaps of tutorials about how to use it, how very few cover the point that how to sync two folders, which I believe is the most common use.

I’d run rsync -avzP dir1 dir2, but unfortunately, this syncs dir1 under dir2. Some people would then run rsync -avzP dir1 dir2-parent. This could work, but it’s particularly dangerous if you add the --delete option. So how to sync the content of the two folders.

If you run man rsync – not many people would use nowadays, you’d get the very import/useful instructions:

A trailing slash on the source changes this behavior to avoid creating an
additional directory level at the destination. You can think of a trailing /
on a source as meaning “copy the contents of this directory” as opposed to
“copy the directory by name”, but in both cases the attributes of the
containing directory are transferred to the containing directory on the
destination. In other words, each of the following commands copies the files
in the same way, including their setting of the attributes of /dest/foo:
rsync -av /src/foo /dest
rsync -av /src/foo/ /dest/foo

The instructions are there like forever, right? But the first command is tricky where you could override the destination directory with the content of foo, so I’d recommend you to always use the second way:

rsync -avP dir1/ dir2

And it works the same way for remote directories.

wdlinux面板wdcp失效的问题

前些日子帮一个朋友恢复wdcp的数据,恢复完成之后发现站点操作全部执行失败,仔细找了一天无果。后来将wdcp的wdapache、wdphp打开错误日志,看到了一个sudo相关的错误,本来就知道应该是权限导致的问题,现在sudo的错误提示更说明了这一点。
于是乎打开sudo的配置文件/etc/sudoers,发现home是有特殊权限的,于是将home分区重新加载到别的分区,然后在wdcp系统面板中更改了新分区,问题解决。
以前一直没想明白面板用户是怎样管理别的用户的文件的,我太傻了,可以sudo嘛,当然为了安全起见,最好在/etc/sudoer里指定用户可以执行的命令。

为CentOS/Redhat/Fedora添加多个IPv6地址

这年头IPv4地址紧张得要命,但是IPv6地址却泛滥地要命。很多服务器托管商分配IPv6地址的时候一般直接分配/64,也就是2的64次方个地址,比所有的IPv4地址加起来还多。地址多了,加起来也要命,下面介绍两种为CentOS/Fedora/Redhat批量添加多个IPv6地址的方法。

假设要为eth0添加2607:f0d0:1002:11::10 到 2607:f0d0:1002:11::50共41个IPv6地址

Continue reading “为CentOS/Redhat/Fedora添加多个IPv6地址”

交互式shell编程利器expect

手里有几台Linux服务器需要经常添加用户,每次都要登录到相应的机器上去添加,特别麻烦。于是想,可不可以在一台机器上写一个脚本来远程管理其它服务器呢?
目标首先瞄准了我熟悉的PHP-CLI,它有一个开发中的模块ssh2,可以完成相应的功能。这个不想说了,因为用了半天都不行,Bug还太多,建议大家如非必要还是不要用这个模块的好。
没了PHP,很迷茫,然后很幸运地发现了expect。expect是交互式shell编程的利器,可以根据返回值来确定下面发送什么命令,特别好用。我把自己编写的远程增加用户的shell跟大家分享下(需要机器装有expect,没有的自己装吧),脚本如下:
Continue reading “交互式shell编程利器expect”

Linux中文件和目录的权限问题

最近搞了几个VPS玩,VPS一般来说内存都不多,配置轻量级的Nginx+PHP,折腾当中权限问题搞了半天。
大家都知道,Linux中文件和目录都有自己的权限,分为rwx三种,分别代表读、写、执行的权限。但是目录和文件又不一样,不能被写和执行,文件rwx三种权限与目录的对比如下:

权限 文件 目录
r 可以列表该目录中的文件
w 可以在该目录中创建或者删除文件
x 执行 可以搜索或者进入该目录

现在很多的博客代码都提供在线安装插件或者升级等方便的功能,但是如果权限设置的不正确就无法使用,比如《WordPress“执行请求操作,连接信息必需提供”解决方法》中提到就是这样的问题。
Continue reading “Linux中文件和目录的权限问题”

利用Nginx反向代理功能架设Ubuntu升级源


北师大的网络情况以前说过了,学校里必须过验证网关才能上外网。为了方便校内同学方便地(不费流量地)升级Ubuntu,也可以充分利用服务器的资源,做了个Ubutu校内的升级源。机器比较老,没有很大的硬盘,做个源的话至少需要上百G的空间,不太现实。于是Kangzj想了出这个方法,在校内一台能上外网的服务器上反向代理一个速度快的Ubuntu源。我选择的是中科大的Ubuntu源(谢谢),速度可以到10M。非常简单,建了一个虚拟主机,然后就解决问题了,下面附上nginx配置文件:
Continue reading “利用Nginx反向代理功能架设Ubuntu升级源”

分享:Vim命令大全

前阵子一群人为了Vi的荣誉在cnBeata吵到不行,牛编辑器就是牛编辑器,不会因为某些人说说就会改变。这里跟大家分享一个Vim编辑器的命令大全,也给自己存个档(很多命令我也记不全),点击可以看大图,分辨率为1280*800,可以当做壁纸。
vim
PS:Vim是Vi的加强版