Posted on Leave a comment

TERM support in Screen command

When you get the following error message when trying to start screen

Cannot find terminfo entry for 'xterm-256color'.

you will need to find the which TERM is supported:

ls /usr/share/terminfo/x

this will give you a list of supported TERMs i.e.

xterm
xterm-xfree86

set the environment variable:

export TERM=xterm-xfree86

and then run the screen command

TERMINFO='/usr/share/terminfo/' screen
Posted on Leave a comment

Backup Raspberry Pi remotely

To back up your raspberry pi remotely, you will need to know the ip address, then using the following command

ssh pi@xx.x.x.xx “sudo dd if=/dev/mmcblk0 bs=1M | gzip -” | dd of=~/Desktop/pibackup.gz

Replace the xx.x.x.xx with the ip address of your pi, and the final image will be copied to your desktop.

To check from time to time the progress, press “Ctrl + T”, and you will see something like the following:

load: 0.98 cmd: dd 8967 running 0.17u 1.94s
317344+0 records in
317344+0 records out
162480128 bytes transferred in 167.835383 secs (968092 bytes/sec)

To restore the image back you need to restore to SD card

diskutil unmountDisk /dev/disk#
gzip -dc ~/Desktop/pibackup.gz | sudo dd of=/dev/rdisk# bs=1m conv=noerror,sync

 

Posted on Leave a comment

Fixing corrupted Time Machine backup

If you are a MAC user, the following message pop up at times.

“Time Machine completed a verification of your backups. To improve reliability, Time Machine must create a new backup for you.”

This means that:

  • Time machine will delete all your existing backups, and
  • Create a new initial backup

You will loose all your previous backups. So let’s try to fix this.

Step 1. Preparations

Time Machine will save all backups and every piece of meta information into a *.sparsebundle file on your network storage device. So this is the file we need to fix.

In order to access it, you need to connect to your networks device share that contains the backup with Finder. It will hold one or more *.sparsebundle files in its root, one for each Mac that uses this drive with Time Machine.

After that, open a Terminal window and switch to the root (=admin) user with the following command:

sudo su -

Enter your password if you’re asked to do so.

When you see the error message I talked about above for the first time, Time Machine has already flagged your backups *.sparsebundle file as bad. As a first step, we need to undo this:

chflags -R nouchg /Volumes/<name of network share>/<name of backup>.sparsebundle

Make sure to replace <name of network share> and <name of backup> accordingly and give it a while to finish.

Step 2. Mounting your backup

Next, we need to mount your backups *.sparsebundle file to enable your system to run a few checks on it:

hdiutil attach -nomount -noverify -noautofsck /Volumes/<name of network share>/<name of backup>.sparsebundle

his command will return something like this:

/dev/diskX Apple_partition_scheme
/dev/diskXs1 Apple_partition_map
/dev/diskXs2 Apple_HFS

What is important to us is the line containing Apple_HFS or Apple_HFSX(this usually is the last line) which is the device ID followed by the device type. The X will be replaced with a number which will be anywhere between 2 and 6 or even higher. So, you want to take note of the device ID that looks something like /dev/disk2s2 or /dev/disk3s2.

Step 3. Repairing the *.sparsebundle

Now we can finally let OS X do its magic of trying to repair the file. Run the following command after replacing the dummy device ID with your own:

fsck_hfs -drfy /dev/diskXs2

With this kicked of, you may want to go have a coffee or two as this may take anywhere from 15 minutes to multiple hours, depending on the size of your backup and the speed of your network connection.

After the command finished, you’ll either see »The Volume was repaired successfully« or »The Volume could not be repaired«.

Either way, you need to unmount the backup before taking any further steps:

hdiutil detach /dev/diskXs2

Step 4. Finishing touches

If the repair command from the previous step failed, there’s not much you can do about it and your backups are lost for real probably. You should just let Time Machine create a new backup for you.

If it succeeded though, there is a last step we need to take in order to convince Time Machine to keep using the existing backup.

Use the Finder to navigate to the backups *.sparsebundle file and with a right click, choose »Show package contents« to get a look inside. There you’ll find a file called com.apple.TimeMachine.MachineID.plist. Since Time Machine uses this file to mark bad backups, too, we need to modify it slightly.

Open the file with a text editor of your choice and find the line saying

<key>RecoveryBackupDeclinedDate</key>
<date>{any-date-string}</date>

and remove them completely. Next find the lines

<key>VerificationState</key>
<integer>2</integer>

and change them to

<key>VerificationState</key>
<integer>0</integer>

Done. You probably want to eject/unmount the network share from your finder and tell Time Machine to do another backup now.