You are not logged in.

#1 2023-12-29 11:03:17

IQ8QI
Member
Registered: 2023-12-29
Posts: 1

Small bash script to push list of installed packages to github repo

On the wiki I saw that I should consider holding list of installed packages in case of disaster: wiki page
And so I created small script to push list of packages to my github, I plan to put it to cron
Maybe someone will find it helpful.
Also, I am not good with bash so I am open for suggestion

#!/usr/bin/bash
cd ~
git clone https://PERSONAL-ACCESS-TOKEN@github.com/USER/REPO
cd REPO
git pull origin main

FILE_NAME=$(date +"pkg-list-%Y.%m.%d-%T")

touch ./lists/$FILE_NAME.txt
yay -Qqe >> ./lists/$FILE_NAME.txt

FILE_COUNT=$(ls -1 ./lists | wc -l)
if [ $FILE_COUNT -gt 1200 ]; then
        OLDEST_FILE=$(ls -1tr ./lists | head -n 1)
        rm ./lists/$OLDEST_FILE
fi

git add .
git commit -m "Auto-commit: Package list on $FILE_NAME"
git push -u origin main

I wonder if making backup of other things will be beneficial, maybe /etc or ~/.*

Offline

#2 2024-01-06 10:37:00

ua4000
Member
Registered: 2015-10-14
Posts: 421

Re: Small bash script to push list of installed packages to github repo

Hi, a backup of all your data will be beneficial in case of a disaster :-)

To minimize the data volume, you could make 3 batches of prio:
prio1 data : e.g. important personal files, emails, backup every day
prio2 data : e.g. program settings, once a week
prio3 data : backup the whole hard-disk including operating system, once a month

Line out your personal backup strategy, deploy it, use it regular, test the theoretical disaster case : could you read and restore all data ?

https://wiki.archlinux.org/title/System … nce#Backup

Offline

#3 2024-01-06 13:19:00

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,898
Website

Re: Small bash script to push list of installed packages to github repo

Mod note: moving to Community Contributions


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#4 2024-01-06 18:10:45

Stefan Husmann
Member
From: Germany
Registered: 2007-08-07
Posts: 1,391

Re: Small bash script to push list of installed packages to github repo

Do not use yay, especially when there is no need to use it. pacman is your package manager and gives you a list of installed packages.

Offline

#5 2024-01-06 21:56:53

Head_on_a_Stick
Member
From: London
Registered: 2014-02-20
Posts: 7,732
Website

Re: Small bash script to push list of installed packages to github repo

That script makes no sense. Why not just use a single file containing the package list and over-write it every time? Git itself will keep track of the old files anyway.

Note that parsing ls is generally a bad idea, although it won't cause problems in this particular example.

EDIT: just for the record: you can place the files in an array to count them:

files=(.list/*)
echo "${#files[@]}" # returns number of files

Determining the oldest without parsing ls is trickier though, perhaps try something like the `stat` suggestions here.

Last edited by Head_on_a_Stick (2024-01-06 22:17:13)

Offline

Board footer

Powered by FluxBB