PDA

View Full Version : Automatic package backup - just wanted to share...



Orange_and_Green
September 10th, 2008, 10:44 AM
Good morning everybody.

I have been using Ubuntu for two years now and I couldn't be happier with it (^_^). I tend to experiment a lot and, especially in my very first newbie age, quite a few times I ended up ruining my installation and thus being forced to reinstall (by formatting the root partition).

I was growing tired of manually reinstalling all of my packages every time, so I developed a tiny program (that I called aptautosave) that automatically keeps a backup list of the packages installed on the system. So now, after a fresh reinstall, I just execute the autogenerated backup script and have my packages restored automatically.

I tried to make the usage as simple as possible: just by double-clicking the binary once, it self-installs and automatically generates backups. I provided a few advanced options too.

Browsing the forums, I have noticed that Mr./Ms. LaRoza has developed a much more complete System Restore program (http://ubuntuforums.org/showthread.php?t=678665) (to which, quite frankly, mine does not seem to hold a candle...:KSExcellent job Mr./Ms.LaRoza, I will download your project from SourceForge and I am eager to try it. Kudos well in advance.)

Nevertheless, I would still like to share my solution with any fellow Ubuntu user who may have any interest in it or any use for it.

I hope it's OK if I just upload my code onto the forums (it's only a few kilobytes anyway), if anyone can in any way benefit from my work I'd be very happy.

Thank you for taking the time of reading this post, please have a nice day.

Please note that version 2.0 is the old, stable one; Version 3 adds new features and corrects a few minor bugs but is still in preliminary testing stage (hence alpha).

isparkes
September 10th, 2008, 07:33 PM
Just what I was looking for!!!

Kudos

Thanks

Orange_and_Green
September 11th, 2008, 09:05 AM
Really? Oh I'm so glad you liked it! You made my day\\:D/

Besides, I just love your avatar:twisted::twisted:

I still point you to the System Restore thread (http://ubuntuforums.org/showthread.php?t=678665) as they have many other interesting features in their program (backing up fstab, repositories, xorg.conf etc. and a neat GUI on top of that). However, if you have your home mounted on a separate partition and/or backed up regularly and all you need is to restore packages, then I guess you can just execute aptautosave once and then forget about it until you need to format (that's when you'd go to the ~/aptautosave directory and fetch the script). At least, that's what I've been doing so far - I guess I'll be contacting the sysres team and see if maybe we could merge our efforts;)

Thanks again and have a nice day:D

Flimm
September 11th, 2008, 12:25 PM
It looks good! I wish I had this earlier before I reinstalled one my Ubuntu installations!
I do have a feature request: can you use aptitude instead of apt-get? Say I have installed kubuntu-desktop using aptitude, I would like the generated script to contain just

sudo aptitude install kubuntu-desktopnot:

sudo apt-get install kubuntu-desktop a-kde-dependency another-kde-dependency ...
The reason I prefer aptitude to apt-get is that it makes uninstalling easier.

Orange_and_Green
September 11th, 2008, 01:14 PM
Dear Flimm,

thank you for your input. Basically, you are suggesting to include only packages that are marked as manually installed into the script. I can definitely see your point there.

As I am planning to rewrite the whole thing anyway (shared library style as nvteighen suggested), I will certainly look into this idea. By itself, dpkg --get-selections does not discriminate between manually and automatically installed packages, so I would need to take its output and have aptitude process it and tell me what is manually installed and what is automatically installed.

aptautosave is intended to run at every login, therefore it needs to be fast (we don't want a windows-style 6-minute desktop freeze on login do we;))

I have tested "aptitude show" and it seems a bit slow to me, I don't think it is a viable option to have it go through the whole output of dpgk --get-selections at every script generation. Unless of course I find a smarter way to do it (suggestions are very welcome:))

What I certainly could do is to add another script-preprocessing tool (the same way as I added "fixbackup"), that is make a program that will process an existing script before the script is run and double-check it against aptitude. That would add the extra benefit of letting the user choose if they want apt-get (by not preprocessing the script) or aptitude (by doing so).

Thank you very much again for your input. It will be a long work till aptautosave 3.0 but with the help of the community I dare hope for it to become a really beautiful piece of software.

Have a nice day,:KS

Orange_and_Green
September 13th, 2008, 04:26 PM
I have thought of a basic interface for the aptautosave library, I will start working on it right away (but slowly 'cause I'm going to change my job and move to Germany in November so my life outside of my laptop is just as much a mess as aptautosave2.0's source code right now). Any suggestions or comments are very welcome.:)



int aptauto_backup_now();
/*Generate a restore script with the options specified in aptautosave
config file. Create a default config file if it does not exist.
Returns 0 on success and -1 on failure.*/

int aptauto_backup_now_with_options(int longdate, char *target_path);
/*Generate restore script specifying whether the saves are on a daily
or on a login basis, and giving an alternate path for the generated
file.
Params: longdate: 0->one backup per day (if executed more than once
a day, file is overwritten)
nonzero->generate a different script on every run
target_path: if it refers to a valid directory, script is
generated into that directory; if not valid,
then the default ~/aptautosave/ is used.
Returns 0 on success and -1 on failure.*/

int aptauto_set_cache (int cache);
/*Set the cache size for the ~/aptautosave directory. Create a default
configfile if none present.
Params: cache->maximum number of .sh files created in ~/aptautosave/
Returns 0 on success and -1 on failure.*/

int aptauto_set_behaviour (int mode);
/*Set the appropriate flag in aptautsave's configfile as to whether
the saves are on a daily or on a login basis.
Params: mode: 0->one backup per day (if executed more than once a
day, file is overwritten)
nonzero->generate a different script on every run
Returns 0 on success and -1 on failure.*/

int aptauto_autostart(char *path);
/*Write an entry into the system's autostart sequence pointing to the
file specified by path. No check is made as to whether path points
to an instance of aptautosave or just any other file so use with
caution.
Also modifies aptautosave config file accordingly.
Returns 0 on success and -1 on failure.*/

int aptauto_noautostart();
/*Removes all aptautosave-related entries from the system's autostart.
Also modifies aptautosave config file accordingly.
Returns 0 on success and -1 on failure.*/

int aptauto_getoptions(int *cache, char *mode, char *path);
/*Writes the contents of the aptautosave config file into the parameters.
Params: cache: maximum number of files in the ~/aptautosave folder.
mode: lsb = 0-> backup on a daily basis
lsb = 1-> one new script at every login
bit #2 = 0-> autostart
bit #2 = 1-> no autostart
Returns 0 on success and -1 if read error occurred.*/

int aptauto_restore_defaults(char *path);
/*Erases the aptautosave config file (if one exists) and writes a new
one with default values.
Returns 0 on success and -1 if new file could not be written.*/

int aptauto_fix_backup (char *scripts);
/*Checks the (space-separated) scripts in the parameter string and
removes any packages not featured in apt-get's package index files.
Needed when restoring package list after upgrading ubuntu to a
different version and/or when repositories have been removed.
Generates a new script into the same directory of the old one,
appending the string "-fixed" to its name. Old script is not
changed.
Returns 0 if at least one of the scripts in the parameter was
valid, else-1*/

int aptauto_aptitude(char *scripts);
/*For every (space-separated) script in the parameter, creates a new
script in the same directory (with "-aptitude" appended to its
name) that uses aptitude instead of apt-get and includes only
manually-installed (i.e. top level) packages.
Returns 0 if at least one of the scripts in the parameter was
valid, else-1*/


Have a nice day everyone. Will keep you informed. Back to work now...

nvteighen
September 13th, 2008, 06:31 PM
Interesting... Looks good to me so far!

Orange_and_Green
September 15th, 2008, 05:07 PM
Thank you for the patience to look into my code nvteighen :) I really appreciate your support.

Before actually starting to implement aptautosave.c, I have spent the last few days working on a library that gives generic services to the aptautosave program (such as determining the user's home, dumping shell command output to tempfile etc.). It compiles so far but I haven't tested it yet, should be up tomorrow [-o< As I know myself, I expect it to be VERY buggy LOL ](*,)

I figured it *might* be of interest to other projects unrelated to aptautosave as well. After that, I'll be happily implementing :)

I'll keep you updated. thank you everybody, have a nice day :KS

Orange_and_Green
September 16th, 2008, 12:38 PM
:cool:Ok, ready at last. I wrote this library and had a very preliminary test program run through all of the functions with a couple of parameter combinations... So far, it seems tp work:popcorn:

I called it libscout as it helps programs to locate their whereabouts (user home, program path, desktop environment, autostart sequence and such).

Next, I'll be going for the aptautosave library. Shouldn't be as long a work this time since libscout implements most low-level functionalities... but you never know:lolflag:

The .h is well commented, the .c much less... adding that to the todo list too.

I'll keep you updated. Thanks well in advance to any kind souls who take interest in this project.

I wish a fantastic day to all dwellers of the Ubuntu Universe
(and multiverse too) :P)

Orange_and_Green
September 19th, 2008, 03:36 PM
libscout -> fixed, added new functions, basic testing
libaptautosave -> implemented, basic testing
main programs: (aptautosave, fixaptitude, fixbackup) -> compiled, a minor glitch on a message to shell I am going to work on, but general functionality seems OK.

Basic usage is still the same (untar the package somewhere, double click on "aptautosave" and get your freshly-baked restore scripts from "aptautosave" directory in your home), hopefully source code is a little cleaner and usable by other developers as well.

Looking forward to your comments
Have a nice weekend everyone:KS

EDIT: Transfered all downloads to the first post. Removing the attachments here to save server space.

Nxion
October 1st, 2008, 03:36 PM
Good morning everybody.

I have been using Ubuntu for two years now and I couldn't be happier about it (^_^). I tend to experiment a lot with it and, especially in my very first newbie age, quite a few times I ended up ruining my installation and thus being forced to reinstall (by formatting the root partition).

I was growing tired of manually reinstalling all of my packages every time, so I developed a tiny program (that I called aptautosave) that automatically keeps a backup list of the packages installed on the system. So now, after a fresh reinstall, I just execute the autogenerated backup script and have my packages restored automatically.

I tried to make the usage as simple as possible: just by double-clicking the binary once, it self-installs and automatically generates backups. I provided a few advanced options too.

Browsing the forums, I have noticed that Mr./Ms. LaRoza has developed a much more complete System Restore program (http://ubuntuforums.org/showthread.php?t=678665) (to which, quite frankly, mine does not seem to hold a candle...:KSExcellent job Mr./Ms.LaRoza, I will download your project from SourceForge and I am eager to try it. Kudos well in advance.)

Nevertheless, I would still like to share my solution with any fellow Ubuntu user who may have any interest in it or any use for it.

I hope it's OK if I just upload my code onto the forums (it's only a few kilobytes anyway), if anyone can in any way benefit from my work I'd be very happy.

Thank you for taking the time of reading this post, please have a nice day.

Amazing script, I love it, Just what I was looking for :)

Orange_and_Green
October 1st, 2008, 03:53 PM
Really? Thanks, I'm so glad :KS

What version have you tried, 2.0 or alpha3? I've only had the chance to test alpha3 on 2 machines so far, so any success or bug reports are very welcome.

telltommy
October 16th, 2008, 10:43 AM
cant get it to install, not sure what i need to do.when i try to download i get:
could not be opened because the associated helper aplication does not exist. Change the association in your preferences?

nvteighen
October 16th, 2008, 12:05 PM
cant get it to install, not sure what i need to do.when i try to download i get:
could not be opened because the associated helper aplication does not exist. Change the association in your preferences?

Eh, why don't you just try to save it? (You're trying to open it from /tmp).

telltommy
October 16th, 2008, 09:46 PM
ok i saved it now i don't know where it is and how to open it and get it working.

Orange_and_Green
October 16th, 2008, 10:56 PM
Hello telltommy,

I'll do my best to give you detailed instructions on how to download and use my program.

1)Go to Edit->Preferences in your browser window. Select the "main" tab at the top, then select "always ask me where to save files". This will help you manage your other downloads as well.

2)Click on the link of your choice on the top message in this thread. You can choose to save it wherever you like; for example, in your home folder.

3)Go to Places->Home folder and navigate to the directory where you saved the file; right-click on it and select "extract here".

4)A directory called "aptautosave" (version 2.0) or "libaptautosave" (version 3 alpha) will be created. Enter it, and double-click on the file called "aptautosave".

5)From this moment on, backups will be generated automatically into a directory called "aptautosave" in your home.

I hope this helps. Thank you for your interest, I hope you like my program and find it useful. :KS

telltommy
October 17th, 2008, 01:40 AM
thanks, that was a clear explaination.

nvteighen
October 17th, 2008, 07:59 AM
thanks, that was a clear explaination.
Of course, he's the developer! :D