Few days ago I typed crontab -r instead of crontab -e. Well, my crontab was immediately deleted, without any warning. The first thing that I’ve done was to check if there was some backups on the server. As usual, there was no backups on my server.

So..If you accidentally type crontab -r instead of crontab -e , I have the solution for you:

In the system logs /var/logs/ are stored all crontab-calls of your system and you can easily extract them. Depending on your system you need to  cat and grep all crontab lines from the /var/log/syslog* files like this:

cat /var/log/syslog | grep -i "`which cron`" > cron_recovery_file

`which cron` will automatically be replaced by /usr/sbin/cron on Debian.

You need also extract all data from older messages logs stored as .gz archives:

gzip -d /var/log/syslog*.gz -c | grep -i "`which cron`" >> cron_recovery_file

In this moment you have a file called cron_recovery_file  that contains all your crontab-calls.

Your file will look like this now:

Feb 12 19:00:01 debian-tutorials /USR/SBIN/CRON[53198]: (root) CMD (crontab_command > /dev/null 2>&1)
Feb 12 19:00:01 debian-tutorials /USR/SBIN/CRON[53199]: (root) CMD (/scripts/backups > /dev/null 2>&1)
Feb 12 19:00:01 debian-tutorials /USR/SBIN/CRON[53200]: (root) CMD (mysql -u root --password=************ -e "flush query cache"; > /dev/null 2>&1)
Feb 12 19:09:01 debian-tutorials /USR/SBIN/CRON[53277]: (root) CMD (  [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -type f -cmin +$(/usr/lib/php5/maxlifetime) -print0 | xargs -n 200 -r -0 rm)
Feb 12 19:17:01 debian-tutorials /USR/SBIN/CRON[53288]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Feb 12 19:30:01 debian-tutorials /USR/SBIN/CRON[53293]: (root) CMD (another_crontab_command > /dev/null 2>&1)

Now, you need to start with the first line and copy/paste the call ( denotes the stuff in the brackets after ‘CMD’) to a new textfile which will be your new crontab. Continue Reading…

Vzdump is a utility to make consistent snapshots of OpenVZ containers (and KVM virtual machines in case you are using Proxmox VE).

It fundamentally creates a tar archive of the container’s private area which also includes the CT configuration files.

The following steps are for Debian Squeeze Linux but vzdump can be used on all other linux distributions

1. Install Vzdump on Deian Squeeze:

apt-get install vzdump

You can also download and install vzdump from the follwing link:

http://download.openvz.org/contrib/utils/vzdump/

wget http://download.openvz.org/contrib/utils/vzdump/vzdump_1.2-4_all.deb

Continue Reading…

There are several methods to move Linux to another hard disk on the same server.
But I used Unix dump / restore utility to do this …

Step1. First you need a new hard disk partition in the same way as with previous unit (Linux is running on). I usually use the utility ‘fdisk‘.
Let us suppose that the old drive is /dev/sda and a new one is /dev/sdb.
To view the partition table hda please run ‘fdisk-l  /dev/ sda “which should show something like this:

[email protected]:~# fdisk -l /dev/sda

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0007384e

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        9330    74936320   83  Linux
/dev/sda2            9330        9730     3212289    5  Extended
/dev/sda5            9330        9730     3212288   82  Linux swap

Step2. After this run ‘fdisk /dev/sdb’ and make the same partitions at it. Interactive mode of fdisk utility is well documented and is very intuitive, so I don’t think it would be difficult to perform partitioning.

After this is done, we should make new filesystems at partitions we’ve created:

mkfs -t ext3 /dev/sdb1
mkswap /dev/sdb2

Step3. Now new hard drive preparation is finished and we can proceed with moving Linux to it. Mount new filesystem and change directory to it:

mount /dev/hdb1 /mnt/hdb1
cd /mnt/hdb1

Step4.  Perform moving by command:

dump -0uan -f – / | restore -r -f

When dump/restore procedures are done we should install boot loader to new HDD. Run ‘grub’ utility and execute in it’s console:

root (hd1, 0)
setup (hd1)
quit

Enjoy.

Running a backup script on a server system as a webhosting server can produce high load and longer latencys for other processes  or php pages load slow during backup because the backup script takes too much  CPU resources.

On Linux systems there are many utilities available for the programming to set the CPU for a appliaction or a script.

In this tutorial we will use nice.

To reduce the CPU priority, use the following command:

/usr/bin/nice -n 19 /location/of/your/script/backup.sh

The -n parameter can be in the range from -20 to 19.  Lower numbers means higher priority.

 

Rsync is often used for backup systems, with options such as:

-A --acls       : preserve the ACL, if used

-X --xattrs     : preserve extended attributes, if used

-H --hard-links : detect and preserve hard links

-a --archive    : resources and preserve the usual attributes: symbolic links, devices and special files,
user and group ownership, permissions and schedules

In addition to these stock options, rsync has many other.

Each has its own recipe, but I’d like to share two useful features :

Continue Reading…

Page 1 of 3123