Шукати в цьому блозі

четвер, 4 жовтня 2018 р.

git - відновлення пошкодженого локального репозиторію

Отримав нещодавно, після "раптового" зникнення електроенергії, помилку
error: object file .git/objects/52/29e2cbdd8cd8d8bef72431eba74fd70455e734 is empty
error: object file .git/objects/52/29e2cbdd8cd8d8bef72431eba74fd70455e734 is empty
fatal: loose object 5229e2cbdd8cd8d8bef72431eba74fd70455e734 (stored in .git/objects/52/29e2cbdd8cd8d8bef72431eba74fd70455e734) is corrupt
Постала задача відновити репозиторій.
Виявилося, що зробити це відносно просто:
mv -v .git .git_old &&            # remove old git
git init &&                       # initialise new repo
git remote add origin "${url}" && # link to old repo
git fetch &&                      # get old history
git reset origin/master --mixed   # force update to old history
Також до уваги пропонується наступний скрипт (чесно взятий звідси):
#!/bin/bash

# Author: Zoey Llewellyn "Zobean" Hewll
#
# Usage: fix-git [REMOTE-URL]
#   Must be run from the root directory of the repository.
#   If a remote is not supplied, it will be read from .git/config
# 
# For when you have a corrupted local repo, but a trusted remote.
# This script replaces all your history with that of the remote.
# If there is a .git, it is backed up as .git_old, removing the last backup.
# This does not affect your working tree.
#
# This does not currently work with submodules!
# This will abort if a suspected submodule is found.
# You will have to delete them first
# and re-clone them after (with `git submodule update --init`)
#
# Error codes:
# 1: If a url is not supplied, and one cannot be read from .git/config
# 4: If the url cannot be reached
# 5: If a git submodule is detected


if [[ "$(find -name .git -not -path ./.git | wc -l)" -gt 0 ]] ;
then
    echo "It looks like this repo uses submodules" >&2
    echo "You will need to remove them before this script can safely execute" >&2
    echo "Then use \`git submodule update --init\` to re-clone them" >&2
    exit 5
fi

if [[ $# -ge 1 ]] ;
then
    url="$1"
else
    if ! url="$(git config --local --get remote.origin.url)" ;
    then
        echo "Unable to find remote 'origin': missing in '.git/config'" >&2
        exit 1
    fi
fi
url_base="$(echo "${url}" | sed -E 's;^([^/]*://)?([^/]*)(/.*)?$;\2;')"
echo "Attempting to access ${url_base} before continuing"
if ! wget -p "${url_base}" -O /dev/null -q --dns-timeout=5 --connect-timeout=5 ;
then
    echo "Unable to reach ${url_base}: Aborting before any damage is done" >&2
    exit 4
fi

echo
echo "This operation will replace the local repo with the remote at:"
echo "${url}"
echo
echo "This will completely rewrite history,"
echo "but will leave your working tree intact"
echo -n "Are you sure? (y/N): "

read confirm
if ! [ -t 0 ] ; # i'm open in a pipe
then
    # print the piped input
    echo "${confirm}"
fi
if echo "${confirm}"|grep -Eq "[Yy]+[EeSs]*" ; # it looks like a yes
then
    if [[ -e .git ]] ;
    then
        # remove old backup
        rm -vrf .git_old | tail -n 1 &&
        # backup .git iff it exists
        mv -v .git .git_old
    fi &&
    git init &&
    git remote add origin "${url}" &&
    git config --local --get remote.origin.url | sed 's/^/Added remote origin at /' &&
    git fetch &&
    git reset origin/master --mixed
else
    echo "Aborting without doing anything"
fi

пʼятниця, 21 вересня 2018 р.

Список великих таблиць у MySQL

Стала задача, з'ясувати таблиці та індекси займають більш за все місця. Одне з можливих рішень - запит до самої БД:
SELECT CONCAT(table_schema, '.', table_name),
       CONCAT(ROUND(table_rows / 1000000, 2), 'M')                                    rows,
       CONCAT(ROUND(data_length / ( 1024 * 1024 * 1024 ), 2), 'G')                    DATA,
       CONCAT(ROUND(index_length / ( 1024 * 1024 * 1024 ), 2), 'G')                   idx,
       CONCAT(ROUND(( data_length + index_length ) / ( 1024 * 1024 * 1024 ), 2), 'G') total_size,
       ROUND(index_length / data_length, 2)                                           idxfrac
FROM   information_schema.TABLES
ORDER  BY data_length + index_length DESC
LIMIT  10;

Отримуємо вивід на кшталт наступного:
+---------------------------------------+---------+--------+-------+------------+---------+
| CONCAT(table_schema, '.', table_name) | rows    | DATA   | idx   | total_size | idxfrac |
+---------------------------------------+---------+--------+-------+------------+---------+
| zabbix.history_uint                   | 492.87M | 12.36G | 9.40G | 21.76G     |    0.76 |
| zabbix.trends_uint                    | 38.00M  | 1.55G  | 0.81G | 2.36G      |    0.52 |
| zabbix.events                         | 8.82M   | 0.84G  | 1.09G | 1.93G      |    1.30 |
| zabbix.history                        | 20.60M  | 0.89G  | 0.76G | 1.65G      |    0.85 |
| zabbix.event_recovery                 | 2.69M   | 0.35G  | 0.31G | 0.66G      |    0.89 |
| zabbix.problem                        | 1.40M   | 0.20G  | 0.26G | 0.46G      |    1.29 |
| zabbix.items                          | 0.11M   | 0.10G  | 0.03G | 0.12G      |    0.27 |
| zabbix.history_str                    | 0.97M   | 0.08G  | 0.04G | 0.11G      |    0.46 |
| zabbix.trends                         | 1.07M   | 0.04G  | 0.02G | 0.06G      |    0.53 |
| zabbix.triggers                       | 0.05M   | 0.03G  | 0.00G | 0.03G      |    0.16 |
+---------------------------------------+---------+--------+-------+------------+---------+
10 rows in set (8.62 sec)

вівторок, 10 липня 2018 р.

Як визначити дистрибутив та версію Linux?

В принципі Linux це ядро, але знати версію ядра це не еквівалент того, що ми одразу можемо дізнатися щось про дистрибутив системи. А от у останньому допоможе пакет inxi.
Запускаємо:
inxi -S
і дізнаємося дещо значно більше ніж просто про версію ядра.
$ inxi -S
System:    Host: askue Kernel: 2.6.32-573.22.1.el6.x86_64 x86_64 bits: 64 Console: tty 2
           Distro: CentOS release 6.7 (Final)
або
$ inxi -S
System:    Host: olden Kernel: 4.9.0-7-amd64 x86_64 (64 bit) Desktop: Cinnamon 3.2.7
           Distro: Debian GNU/Linux 9 (stretch)
Але й це не все, про систему можна та "залізо" можна дізнатися більше якщо запустити inxi з параметром -F:

$ inxi -F
System:    Host: askue Kernel: 2.6.32-573.22.1.el6.x86_64 x86_64 bits: 64 Console: tty 2
           Distro: CentOS release 6.7 (Final)
Machine:   Device: server System: Supermicro product: X10DRH v: 123456789 serial: 123456789
           Mobo: Supermicro model: X10DRH-C v: 1.01 serial: NM15AS011867
           UEFI [Legacy]: American Megatrends v: 2.0 date: 12/17/2015
CPU(s):    2 6 core Intel Xeon E5-2620 v3s (-MT-MCP-SMP-) cache: 30720 KB
           clock speeds: max: 2399 MHz 1: 2399 MHz 2: 2399 MHz 3: 2399 MHz 4: 2399 MHz 5: 2399 MHz 6: 2399 MHz
           7: 2399 MHz 8: 2399 MHz 9: 2399 MHz 10: 2399 MHz 11: 2399 MHz 12: 2399 MHz 13: 2399 MHz 14: 2399 MHz
           15: 2399 MHz 16: 2399 MHz 17: 2399 MHz 18: 2399 MHz 19: 2399 MHz 20: 2399 MHz 21: 2399 MHz
           22: 2399 MHz 23: 2399 MHz 24: 2399 MHz
Graphics:  Card: ASPEED ASPEED Graphics Family
           Display Server: N/A driver: N/A tty size: 211x53 Advanced Data: N/A for root out of X
Network:   Card-1: Intel I350 Gigabit Network Connection driver: igb
           IF: eth0 state: up speed: 1000 Mbps duplex: full mac: 0c:c4:7a:6c:de:ce
           Card-2: Intel I350 Gigabit Network Connection driver: igb
           IF: eth1 state: up speed: 1000 Mbps duplex: full mac: 0c:c4:7a:6c:de:cf
Drives:    HDD Total Size: 1999.3GB (0.2% used)
           ID-1: /dev/sda model: SMC3108 size: 1999.3GB
Partition: ID-1: / size: 9.5G used: 1.5G (17%) fs: ext4 dev: /dev/dm-0
           ID-2: /boot size: 477M used: 57M (13%) fs: ext4 dev: /dev/sda1
           ID-3: swap-1 size: 1.07GB used: 0.00GB (0%) fs: swap dev: /dev/dm-1
RAID:      No RAID devices: /proc/mdstat, md_mod kernel module present
Sensors:   System Temperatures: cpu: No active sensors found. Have you configured your sensors yet? mobo: N/A
Info:      Processes: 478 Uptime: 314 days Memory: 573.9/15838.4MB Init: Upstart runlevel: 3
           Client: Shell (bash) inxi: 2.3.56 
$ inxi -F
System:    Host: olden Kernel: 4.9.0-7-amd64 x86_64 (64 bit) Desktop: Cinnamon 3.2.7
           Distro: Debian GNU/Linux 9 (stretch)
Machine:   Device: desktop Mobo: ASUSTeK model: P5Q SE PLUS v: Rev 1.xx BIOS: American Megatrends v: 2204 date: 08/28/2009
CPU:       Quad core Intel Core2 Quad Q8300 (-MCP-) cache: 2048 KB 
           clock speeds: max: 2499 MHz 1: 2003 MHz 2: 2003 MHz 3: 2003 MHz 4: 2003 MHz
Graphics:  Card: NVIDIA G73 [GeForce 7600 GS]
           Display Server: X.Org 1.19.2 driver: nvidia Resolution: 1920x1080@60.00hz, 1920x1080@60.00hz
           GLX Renderer: GeForce 7600 GS/PCIe/SSE2 GLX Version: 2.1.2 NVIDIA 304.137
Audio:     Card Intel 82801JI (ICH10 Family) HD Audio Controller driver: snd_hda_intel
           Sound: Advanced Linux Sound Architecture v: k4.9.0-7-amd64
Network:   Card: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller driver: r8169
           IF: eth0 state: up speed: 1000 Mbps duplex: full mac: 20:cf:30:19:46:f7
Drives:    HDD Total Size: 2320.5GB (35.7% used)
           ID-1: /dev/sdb model: WDC_WD20EFRX size: 2000.4GB
           ID-2: /dev/sda model: SAMSUNG_HD321KJ size: 320.1GB
Partition: ID-1: / size: 9.1G used: 3.1G (36%) fs: ext4 dev: /dev/sda1
           ID-2: /usr size: 14G used: 11G (79%) fs: ext4 dev: /dev/sda6
           ID-3: /home size: 184G used: 161G (93%) fs: ext4 dev: /dev/sda5
           ID-4: /var size: 74G used: 13G (18%) fs: ext4 dev: /dev/sda7
           ID-5: /tmp size: 11G used: 29M (1%) fs: ext4 dev: /dev/sda9
           ID-6: swap-1 size: 3.00GB used: 0.08GB (3%) fs: swap dev: /dev/sda8
Sensors:   System Temperatures: cpu: 35.5C mobo: 47.0C gpu: 71C
           Fan Speeds (in rpm): cpu: 2220 psu: 0 sys-1: 1117
Info:      Processes: 281 Uptime: 1:03 Memory: 3754.7/7987.1MB Client: Shell (bash) inxi: 2.3.5 
ну й не забуваймо про
man inxi
А ще можна уважно подивитися у бік:
$ cat /etc/*-release
$ cat /etc/issue

пʼятниця, 8 червня 2018 р.

jks від Приватбанку конвертувати в pem та/або p12

Отримати список аліасів
$ keytool -list -keystore pb_2711913473.jks
Enter keystore password:  

Keystore type: JKS
Keystore provider: SUN

Your keystore contains 1 entry

pb_sign_2711913473, 18 січ. 1970, PrivateKeyEntry, 
Certificate fingerprint (SHA1): A6:32:B1:C6:13:B0:64:E3:D1:42:AC:B4:4E:B4:1E:E5:23:72:11:CC

Експортувати у pem:
$ keytool -exportcert -alias pb_sign_2711913473 -keystore pb_2711913473.jks -rfc -file pb_2711913473.pem
Enter keystore password:  
Certificate stored in file <pb_2711913473.pem>

Згенерувати jks на підставі створеного pem:
$ rm pb_2711913473.jks
$ keytool -import -trustcacerts -keystore pb_2711913473.jks -storepass PASSWORD -noprompt -file pb_2711913473.pem -alias pb_sign_2711913473
Certificate was added to keystore

Згенерувати p12 на підставі створеного jks:
$ keytool -importkeystore -srckeystore pb_2711913473.jks -destkeystore pb_2711913473.p12 -srcstoretype jks -deststoretype pkcs12
Enter destination keystore password:  
Re-enter new password: 
Enter source keystore password:  
Entry for alias pb_sign_2711913473 successfully imported.
Import command completed:  1 entries successfully imported, 0 entries failed or cancelled