You need to join this project to post message / question. See Help for details.

Blog

Differential vs. Incremental Backup

Added by ruby about 1 month ago

Defintion

  1. Incremental backups catch day-to-day changes
  2. Differential backups catch all changes since full

Example

  1. Sets
    1. Day 1: {0, 1, 2, D}
    2. Day 2: {0, 1, 2a, 3}
    3. Day 3: {0a, 1a, 2a, 3, 4}
  2. Differential backup
    1. The first archive: {0, 1, 2, D}
    2. The second archive: {2a, 3}
    3. The third archive: {0a, 1a, 2a, 3, 4}
  3. Incremental Backup
    1. The first archive: {0, 1, 2, D}
    2. The second archive: {2a, 3}
    3. The third archive: {0a, 1a, 4}

Linux: duplicated account identities

Added by ruby about 1 month ago

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

Added by icy 7 months ago  »  Votes: 2/2

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

Added by icy 7 months ago  »  Votes: 2/2

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:

  1. Shut down the VirtualBox guest
  2. 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
    
  3. Copy all data from the old_disk to the new one
    1 VBoxManage clonehd --existing /path/to/old_disk.vmdk /path/to/new_disk.vdi
    
  4. (Attaching new_disk, step 1) Execute the command VBoxManage showvminfo my_vbox | grep Controller and locate a free port/device. For example, from the output
    1 $ 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:
  5. (Attaching new_disk, step 2) Execute the command
    1 VBoxManage storageattach my_vbox --storagectl "IDE Controller" \
    2            --port 0 --device 1 --type hdd --medium /path/to/new_disk.vdi
    
  6. Now boot up the client my_vbox. After logging in to the client, you have to use standard linux tool such as: cfdisk, fdisk, resize2fs to resize the partition. If your partition is encrypted using LUKS, you must execute the command cryptsetup resize before invoking resize2fs. For example
    1 $ cryptsetup luksOpen /dev/sdb1 foobar
    2 $ cryptsetup resize foobar
    3 $ resize2fs /dev/mapper/foobar
    
  7. After you invoke resize2fs, please use the command mount to attach the device to some point on the system, and check if the new partition/disk has the expected size.
  8. Shutdown the VirtualBox client my_vbox
  9. Attach the new_disk to expected location: In old example, the old disk old_disk is 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 command
    1 VBoxManage storageattach my_vbox --storagectl "IDE Controller" \
    2            --port 0 --device 0 --type hdd --medium /path/to/new_disk.vdi
    
  10. Start the client again :)

(linux) Assign new IP address to an inteface (2 comment)

Added by icy 7 months ago  »  Votes: 1/1

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

Added by icy 8 months ago  »  Votes: 1/1

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

Added by icy 9 months ago  »  Votes: 2/2

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:

  1. pacman by Arch Linux, ArchBang
  2. dpkg/apt-get by Debian, Ubuntu
  3. yum/rpm by 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)

Added by icy 9 months ago  »  Votes: 1/1

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

Added by icy 10 months ago  »  Votes: 1/1

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

  1. The Knife is used on another host (it's my laptop!)
  2. Chef api server is started by chef-server -e production -d on the host 10.0.0.94. Chef API will listen on the port 4000 which is inaccessible from my laptop (this is due to firewall).
  3. Nginx is used as a front-end for chef api server, and it is running on the same host as Chef API server. nginx will serve Chef API on the port :81. The configuration is
     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;
     8   }
     9 }
    
  4. 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)

Added by icy 10 months ago  »  Votes: 1/1

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:

  1. Using the add-on Compatibility Reporter
    1. Install Firefox 3
    2. Install "Delicious Bookmark" for Firefox 3
    3. Upgrage Firefox (so you get Firefox 4). Firefox will disable "Delicious Bookmark" (but the extension won't be removed)
    4. Install the add-on Compatibility Reporter, then restart Firefox and enable Delicious Bookmark in the Add-ons page.
    5. This method is still working if you've just updated your Firefox, and you haven't deleted the extension yet.
  2. Tricking Firefox4's installer
    1. Install Firefox 4
    2. 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)
    3. Save the extension as an XPI file, for example delicious_bookmarks-2.1.106-fx.xpi. This is a zip archive
    4. Make a temporary directory, uncompress the .xpi to 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 ./
      
    5. Now you get new XPI file, and Firefox4 accepts it to process installation, though Firefox would complain about untrusted source of XPI (as we removed the signatures from META-INF)
    6. Explanation
      1. Line 1: make temporary directory
      2. Line 2: Switch to tmp and decompress the original XPI file
      3. Line 3: Make a backup of the original XPI file
      4. Line 4: Remove the original XPI file
      5. Line 5: Remove all signatures
      6. 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.
      7. Line 7: Compress the directory and create new (untrusted) XPI file

1 2 3 ... 29 Next »

Also available in: Atom