Linux

I obviously wanted to make sure my save games and save states where all not only backed up to another local computer in my house(via rsync) but i also wanted an offsite copy. After looking around i decided to go with idrive. 5G free and they have a CLI that is supported on a surprising number of OS’s including Linux.

Setup

I set up an account and downloaded the Linux 64 bit version. It consists of a single executable that i then put in /storage/idrive. unfortunetly it requers libpopt which is not a part of lakka and lakka has no package management.

$ ldd idevsutil
 linux-vdso.so.1 (0x00007ffd0f5fe000)
 libpopt.so.0 => not found
 libdl.so.2 => /lib/libdl.so.2 (0x00007fd8a9486000)
 libc.so.6 => /lib/libc.so.6 (0x00007fd8a90e7000)
 /lib64/ld-linux-x86-64.so.2 (0x00007fd8a968a000)

Well shit. To fix this I started up a VirtualBox of, I think Arch, and scp’ed over libpopt.so.0 to /storage/idrive/. Problem solved, even if it is super hacky.

Configuration

We first have to configure our account to be able to use the CLI tool. You should create a file with your private encryption key password and another file containing your idrive password.  You can then run the –config-account option….

# ./idevsutil --config-account --enc-type=PRIVATE --pvt-key=/storage/idrive/pvt_key --user=USER_NAME --password-file=/storage/idrive/passwd
connection established

<tree message="SUCCESS" desc="ACCOUNT CONFIGURED" ⁄>

Success!. You now must fine the cmd utility server IP Address associated with your account. To do so run…

# ./idevsutil --getServerAddress USER_NAME
Password:

<tree message="SUCCESS" cmdUtilityServer="evs84.idrive.com" cmdUtilityServerIP="IP_ADDRESS" webApiServer="evsweb84.idrive.com" webApiServerIP="IP_ADDRESS"/>

HAZA! We can now finally start backing our things up.

Backing up

Create a file listing all the files and directors you want to back up. I called my file /storage/idrive/manifest

/storage/savestates
/storage/savefiles
/storage/playlists
/storage/idrive

I decided to also back up the idrive directory because it was a bit of a pain to set up. Because of this you need to add the –tmp=/tmp/idrive arguemnt to your commands. If you dont it will faile to back up some temporary files that you actually dont even want.

# ./idevsutil --pvt-key=/storage/idrive/pvt_key  --files-from=/storage/idrive/manifest / USER_NAME@CLI_IP_ADDRESS::home/lakka --password-file=/storage/idrive/passwd --temp=/tmp/idrive
connection established
building file list ...
====================================================================================
| FILE SIZE | TRANSFERED SIZE | TOTAL SIZE | PERCENTAGE | TRANSFER RATE | FILENAME |
====================================================================================
[ 2712553] [ 0] [ 46780031] [100%] [ 0.00kB/s] [storage/idrive/idevsutil]
[ 48240] [ 0] [ 46780031] [100%] [ 0.00kB/s] [storage/idrive/libpopt.so.0]

*** REMOVED DATA ***

[ 13179] [ 0] [ 46780031] [100%] [ 0.00kB/s] [storage/savestates/Nestopia/Darkwing Duck (USA).state.auto]
[ 430181] [ 0] [ 46780031] [100%] [ 0.00kB/s] [storage/savestates/Snes9x/Legend of Zelda, The - A Link to the Past (USA).state.auto]

sent 3500 bytes received 40 bytes 2360.00 bytes/sec

CRON

lastly we set up cron and or small shell script to back things up every 10 min.

Cron entry:

0,10,20,30,40,50 * * * * /storage/idrive/backup.sh > /storage/idrive/backup_`

1
date +"%H%M"`
.log 2>&1

(Not sure why wordpress is freaking the fuck out)

The backtick voodo is so i get an hours worth of backup logs that overwrite themselves after one hour. Helpful if there is an issue and i don’t have to worry about rotating or deleting old logs as it does that itself.

And the contents of the backup.sh is…

#!/bin/bash

LD_LIBRARY_PATH=/storage/idrive /storage/idrive/idevsutil --pvt-key=/storage/idrive/pvt_key --files-from=/storage/idrive/manifest / xxann5@173.255.9.166::home/lakka --password-file=/storage/idrive/passwd --temp=/tmp/idrive
date

And thats it. I can now relax and know that every 10 min all my save data will be nice and safe.

Share Button

Had an odd issue a few weeks back. A process was not behaving as it should. After doing some digging I found out that the the only way it could behave like it was, was if an environment variable was set incorrectly. The odd part was that /proc/$$/environ was showing that it was set correctly.

After doing some research and playing with gdb a bit (thankfully this was a test environment) I found out that /proc/$$/environ does not give you what you think it gives you!

on to the why.

When a process starts the create_elf_tables function gets called. This function creates and populates a mm_struct data structure. This structure, among other things, contains env_start and env_end, which are the memory address of the begging and end of the environment variable data in the stack.

To get the environment variable information the proc file system reads mm_struct to get he start and end values where the environment variables are located. This is done in the environ_read function.

So why is this not giving me what i want? Well when the process is created in memory there is no buffer in the stack to add more environment variables or to make existing environment variables longer.  So when the process creates a new environment variable or modifies an existing one the environment variables get moved to the heap and the environ symbol is changed to point to the new location. The mm_struct however, is not changed. Which is not necessarily a bad thing but since the proc file system looks at the mm_struct you get the environment at execution time and not the current environment.

this behavior is simple to see.

1
2
3
4
5
6
7
$ echo $FOO

$ cat /proc/$$/environ |tr '\0' '\n' |grep FOO
$ export FOO=BAR
$ echo $FOO
BAR
$ cat /proc/$$/environ |tr '\0' '\n' |grep FOO

For the hell of it I was playing around with ptrace and made an small program that attaches to a process parses the elf structure, finds the environ symbol and then prints out the
current environment variables. The code is crap and the thing barely works(well sometimes it barely works) I was just fooling around. Its allot easier (and safer) to start up GDB and do a “show environ“.

Share Button