Blog
Differential vs. Incremental Backup
Defintion
- Incremental backups catch day-to-day changes
- Differential backups catch all changes since full
Example
- Sets
- Day 1: {0, 1, 2, D}
- Day 2: {0, 1, 2a, 3}
- Day 3: {0a, 1a, 2a, 3, 4}
- Differential backup
- The first archive: {0, 1, 2, D}
- The second archive: {2a, 3}
- The third archive: {0a, 1a, 2a, 3, 4}
- Incremental Backup
- The first archive: {0, 1, 2, D}
- The second archive: {2a, 3}
- The third archive: {0a, 1a, 4}
Linux: duplicated account identities
Linux system supports accounts with duplicated identities
1 $ useradd -u 0 -g 0 toor
2 useradd: UID 0 is not unique
3
4 $ useradd -u 0 -g 0 toor -o
5 # no error reported
This feature is very useful if you have multiple authentication sources on your system :)
There is another way: edit the file /etc/passwd directly and then use the command pwconv to transfer your changes to /etc/shadow. Please note that the order of accounts in /etc/passwd is important.
Linux: get system uptime
How to get the system's uptime? Try any of the following commands
1 $ uptime
2 16:25:59 up 7:37, 3 users, load average: 0.43, 0.66, 0.58
3
4 $ w |head -1
5 16:29:50 up 7:41, 3 users, load average: 0.04, 0.37, 0.48
6
7 $ cat /proc/uptime
8 27910.58 20588.15
9
10 $ ps -p 1 -o "%t"
11 ELAPSED
12 07:48:15
13
14 $ ps -p 1 -o etime
15 ELAPSED
16 07:48:22
More ? Please wait ... ;)
Virtualbox: Enlarge a disk
Keywords: Virtualbox, disk, encrypt, luks
Problem: You want to enlarge a disk foobar.vmdk for a VirtualBox Linux client (named my_vbox). There is only ONE partition on the disk, and the partition may be encrypted (using LUKS).
Steps:
- Shut down the VirtualBox guest
- Create a new disk with expected size by the command. For example, to create a disk of size 10GB:
1 VBoxManage createhd --filename /path/to/new_disk.vdi --size 10000 --format VDI --variant Standard - Copy all data from the
old_diskto the new one1 VBoxManage clonehd --existing /path/to/old_disk.vmdk /path/to/new_disk.vdi - (Attaching
new_disk, step 1) Execute the commandVBoxManage showvminfo my_vbox | grep Controllerand locate a free port/device. For example, from the output1 $ VBoxManage showvminfo arch |grep Controller 2 Storage Controller Name (0): IDE Controller 3 .... 4 IDE Controller (0, 0): /mnt/virtualbox/vmdisks/old_disk.vdi (UUID: ...) 5 IDE Controller (1, 0): /mnt/virtualbox/vmdisks/arch2.vdi (UUID: ...)
you may use the free device "1". Now attach the new disk to that free device/port: - (Attaching
new_disk, step 2) Execute the command1 VBoxManage storageattach my_vbox --storagectl "IDE Controller" \ 2 --port 0 --device 1 --type hdd --medium /path/to/new_disk.vdi - Now boot up the client
my_vbox. After logging in to the client, you have to use standard linux tool such as:cfdisk,fdisk,resize2fsto resize the partition. If your partition is encrypted using LUKS, you must execute the commandcryptsetup resizebefore invokingresize2fs. For example1 $ cryptsetup luksOpen /dev/sdb1 foobar 2 $ cryptsetup resize foobar 3 $ resize2fs /dev/mapper/foobar - After you invoke
resize2fs, please use the commandmountto attach the device to some point on the system, and check if the new partition/disk has the expected size. - Shutdown the VirtualBox client
my_vbox - Attach the
new_diskto expected location: In old example, the old diskold_diskis attached to the port 0 / device 0 of the client, so you have to relocate the disk to that couple of port/device, by the command1 VBoxManage storageattach my_vbox --storagectl "IDE Controller" \ 2 --port 0 --device 0 --type hdd --medium /path/to/new_disk.vdi - Start the client again :)
(linux) Assign new IP address to an inteface (2 comment)
Keywords: Linux, ip
If your system is running well, then how can you add new ip address to an interface without any rebooting?
Ah... there is very simple tool named ip. The tool ip is very powerful and it can do many jobs, but let us first anwser the above question.
1 $ /sbin/ip addr add 10.0.0.95/32 dev eth0
After this command, the interface eth0 will have a new IP address "10.0.0.95". To view the result, you can use ifconfig, or sometimes you have to use ip addr:
1 $ ip addr
2 ....
3 3: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
4 link/ether 00:26:9e:9e:30:8f brd ff:ff:ff:ff:ff:ff
5 inet 10.0.0.95/32 scope global eth0
Final note: When using ip addr, the routing table isn't updated automatically, so you may want to use "route" to update it. Moreover, some services need to be restarted to listen on the new address.
Bash: compare two versions
How to compare two version strings in Bash !?
My small routine may help: Bash Compare Two Versions. Example:
1 $ __version_compare_v1_le_v2 1.1.1 1.1.2
2 # Return 0 (aka TRUE)
3 $ __version_compare_v1_le_v2 2.1.1-1 1.1.1-2
4 # Return 1 (aka FALSE)
5 $ __version_compare_v1_le_v2 1.1.1 2.2.2.4
6 # Return 2 (aka FAILED to compare two different formats)
Wrapper for all Linux package managers
An Arch's pacman-liked package manager for all Linux distributions.
Instead of remembering various options/tools on different OSs, you only need a common way to manipulate packages. Not all options of the native package manager are ported; the tool only provides very basic interface to search, install, remove packages and/or update the system.
Arch's pacman is chosen, as pacman is quite smart when it devides all packages-related operations into three major groups: Synchronize, Query and Remove/Clean up. It has a clean man page, and it is the only tool needed to manipulate official packages on system. (Debian, for example, requires you to use apt-get, dpkg and/or aptitude.)
The tool supports the following types of package manager:
-
pacmanby Arch Linux, ArchBang -
dpkg/apt-getby Debian, Ubuntu -
yum/rpmby Redhat, CentOS, Fedora Core
This program is written by Anh K. Huynh. The source can be found at http://github.com/icy/pacapt/.
Debian: get more spaces by deleteing /var/{cache,lib}/apt/ (1 comment)
Sometimes the system disk is full, and a very quick way to fix the problem is to delete all unnecessary files. The two directories /var/{cache,lib}/apt/ are the first ones you would concern: The cache contains binary files and binary packages for apt-get program, you can safely delete it
$ rm -vf /var/cache/apt/*.bin $ rm -vf /var/cache/apt/archives/*.* $ rm -vf /var/lib/apt/lists/*.*
The following directories should be kept to help apt-get to work fine:
# /partial/ contains partial downloaded files /var/cache/apt/archives/partial/ /var/lib/apt/lists/partial/
Next time when you want to install/update packages, you would use apt-get autoclean first
$ apt-get autoclean $ apt-get update $ # Other apt-get commands
See another post Apt Get Cache Clean
chef-api-server as a nginx's back-end
Thanks to coderanger on #chef
Keywords: chef, merb, ruby
Update 2011/July/21: The problem doesn't happen with Chef-0.10.2. Please ignore this post if you are using Chef-0.10.2 or higher.
If Chef API server is served as a nginx's back-end, you may get trouble when uploading cookbooks to the server. In the following logs, the debug messages show that knife receives wrong location of server api after its PUT action (see line 8 and line 11):
1 $ knife cookbook upload chef-client -l debug
2 DEBUG: Using configuration from /home/pi/.chef/knife.rb
3 INFO: Saving chef-client
4 ....
5 DEBUG: Generated /var/chef-repo/cookbooks/chef-client/metadata.json
6 DEBUG: Signing the request as pi
7 DEBUG: Sending HTTP Request via POST to 10.0.0.94:81//sandboxes # good, knife knows the server's address
8 INFO: Uploading files # good, knife has just received the response from server
9 INFO: Uploading /var/chef-repo/cookbooks/chef-client/....
10 (checksum hex = ...) to http://127.0.0.1:4000/sandboxes/.... # bad, the response from server is wrong
The configuration which causes this problem is as below
- The
Knifeis used on another host (it's my laptop!) Chef api serveris started bychef-server -e production -don the host10.0.0.94.Chef APIwill listen on the port4000which is inaccessible from my laptop (this is due to firewall).Nginxis used as a front-end forchef api server, and it is running on the same host asChef API server.nginxwill serveChef APIon the port:81. The configuration is1 server { 2 listen 10.0.0.94:81; 3 access_log logs/chef-api.acces.log; 4 error_log logs/chef-api.error.log; 5 location / { 6 proxy_pass http://127.0.0.1:4000; 7 proxy_redirect default; 8 } 9 }- A simple digram may help to explain the configuration
Knife --> 10.0.0.94:81 (nginx) --> 127.0.0.1:4000 (chef api server)
So, the configuration proxy_redirect doesn't work as expected. In the source code of sandboxes.rb, the definition of the method create shows that
1 def create
2 # ...
3 # construct successful response
4 self.status = 201
5 location = absolute_url(:sandbox, :sandbox_id => new_sandbox.guid)
6 headers['Location'] = location
7 # ...
8 end
The function absolute_url is invoked to constructe the response header. This function is defined in Merb core library
1 def absolute_url(*args)
2 # FIXME: arrgh, why request.protocol returns http://?
3 # :// is not part of protocol name
4 options = extract_options_from_args!(args) || {}
5 protocol = options.delete(:protocol)
6 host = options.delete(:host)
7 # ...
8 protocol + "://" + host + url(*args)
9 end
Arrgh, there is still a FIXME :) But it isn't related to our problem. As you can see in the code, the host is detected from :host. I don't know where its value is got in Merb, but nginx can help to overwrite it easily:
1 server {
2 listen 10.0.0.94:81;
3 access_log logs/chef-api.acces.log;
4 error_log logs/chef-api.error.log;
5 location / {
6 proxy_pass http://127.0.0.1:4000;
7 proxy_redirect default; # This should have worked :(
8 proxy_set_header Host 10.0.0.94:81; # This work! This tricks Merb!
9 }
10 }
This seems to be buggy: The host shouldn't contain the port (:81 here). But I don't care: At least my Chef works :))
Delicious Bookmark for Firefox 4 (1 comment)
The current version 2.1.106 of Delicious Bookmarks is incompatible with Firefox4. Actually the extension is still working fine; we just don't know to install or enable it :) There are several ways:
- Using the add-on
Compatibility Reporter- Install Firefox 3
- Install "Delicious Bookmark" for Firefox 3
- Upgrage Firefox (so you get Firefox 4). Firefox will disable "Delicious Bookmark" (but the extension won't be removed)
- Install the add-on Compatibility Reporter, then restart Firefox and enable
Delicious Bookmarkin the Add-ons page. - This method is still working if you've just updated your Firefox, and you haven't deleted the extension yet.
- Tricking
Firefox4's installer- Install Firefox 4
- Go to the extension's home page, and download it (Choose
Save link as, otherwise Firefox will try to download and install the extension. You can also try this link https://addons.mozilla.org/firefox/downloads/file/97396/delicious_bookmarks-2.1.106-fx.xpi) - Save the extension as an
XPIfile, for exampledelicious_bookmarks-2.1.106-fx.xpi. This is azip archive - Make a temporary directory, uncompress the
.xpito that directory and modify the meta data of the XPI:1 $ mkdir foobar 2 $ cd foobar; unzip ../delicious_bookmarks-2.1.106-fx.xpi 3 $ cp ../delicious_bookmarks-2.1.106-fx.xpi ../delicious_bookmarks-2.1.106-fx.xpi.backup 4 $ rm -fv ../delicious_bookmarks-2.1.106-fx.xpi 5 $ rm -rfv ./META-INF/ 6 $ sed -i -e 's/maxVersion="[^"]\+"/maxVersion="4.0"/g' install.rdf 7 $ zip -r ../delicious_bookmarks-2.1.106-fx.xpi ./ - Now you get new
XPIfile, and Firefox4 accepts it to process installation, though Firefox would complain aboutuntrusted source of XPI(as we removed the signatures fromMETA-INF) - Explanation
- Line 1: make temporary directory
- Line 2: Switch to
tmpand decompress the original XPI file - Line 3: Make a backup of the original XPI file
- Line 4: Remove the original XPI file
- Line 5: Remove all signatures
- Line 6: Trick Firefox, by updating the maximum version of Firefox that can accept the extension. In my downloaded XPI file, the orignal value of "maxVersion" is
4.0b3pre. - Line 7: Compress the directory and create new (untrusted) XPI file
Also available in: Atom