SSH key to base64 (for bitbucket pipelines)
base64 -w 0 < id_rsa > id_rsa_base64
7 января 2025, 18:36
base64 -w 0 < id_rsa > id_rsa_base64
#!/bin/bash # Environment check SOURCE_HOST_ADDRESS=localhost SOURCE_HOST_USER=$USER TARGET_HOST_ADDRESS=192.168.126.168 TARGET_HOST_USER=targetuser # If migrating from localhost, set this to localhost if [[ ! $SOURCE_HOST_ADDRESS ]] then echo "Please set the current host address in SOURCE_HOST_ADDRESS" exit 1 fi # If migrating from localhost, set this to $USER if [[ ! $SOURCE_HOST_USER ]] then echo "Please set the current host user in SOURCE_HOST" exit 1 fi # If migrating to localhost, set this to localhost if [[ ! $TARGET_HOST_ADDRESS ]] then echo "Please set the new host address in TARGET_HOST_ADDRESS" exit 1 fi # If migrating to localhost, set this to $USER if [[ ! $TARGET_HOST_USER ]] then echo "Please set the new host user in TARGET_HOST_USER" exit 1 fi # Argument check if [[ ! $1 ]] then echo "Please supply a docker volume name, as displayed by the command 'docker volume ls'" exit 1 fi volume_name=$1 # Export the volume from the current instance echo "Exporting volume $volume_name on $SOURCE_HOST_ADDRESS" ssh "$SOURCE_HOST_USER"@"$SOURCE_HOST_ADDRESS" "\ mkdir -p \$HOME/docker-volume-backup docker run \ --rm \ -v $volume_name:/volume-backup-source \ -v \$HOME/docker-volume-backup:/volume-backup-target \ busybox \ sh -c 'cd /volume-backup-source && tar cf /volume-backup-target/backup.tar .' \ " # Transfer the exported volume to the new address echo "Transferring exported volume $volume_name from $SOURCE_HOST_ADDRESS to $TARGET_HOST_ADDRESS" ssh "$TARGET_HOST_USER"@"$TARGET_HOST_ADDRESS" "mkdir -p \$HOME/docker-volume-backup" scp -3 "$SOURCE_HOST_USER"@"$SOURCE_HOST_ADDRESS":./docker-volume-backup/backup.tar \ "$TARGET_HOST_USER"@"$TARGET_HOST_ADDRESS":./docker-volume-backup/backup.tar # Restore the backup echo "Creating volume $volume_name on $TARGET_HOST_ADDRESS" ssh "$TARGET_HOST_USER"@"$TARGET_HOST_ADDRESS" "\ docker volume create $volume_name \ && docker run \ --rm \ -v $volume_name:/volume-backup-target \ -v \$HOME/docker-volume-backup/:/volume-backup-source \ busybox \ sh -c 'cd /volume-backup-target && tar xf /volume-backup-source/backup.tar .' \ " # Clean up residual files echo "Cleaning up unnecessary files" ssh "$SOURCE_HOST_USER"@"$SOURCE_HOST_ADDRESS" "rm -rf \$HOME/docker-volume-backup" ssh "$TARGET_HOST_USER"@"$TARGET_HOST_ADDRESS" "rm -rf \$HOME/docker-volume-backup" echo "Successfully migrated docker volume $volume_name from $SOURCE_HOST_ADDRESS to $TARGET_HOST_ADDRESS"
Host address.com Hostname address.com ServerAliveInterval 55 ForwardAgent yes ProxyCommand nc -x 127.0.0.1:9999 %h %p
define('FS_CHMOD_DIR', 0777);
select enum_range(null::your_type_name);
sudo apt install postgresql postgresql-contrib
su postgres psql ALTER USER postgres PASSWORD '***';
/usr/share/gitlab-runner/clear-docker-cache
# Add Docker's official GPG key: sudo apt-get update sudo apt-get install ca-certificates curl sudo install -m 0755 -d /etc/apt/keyrings sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc sudo chmod a+r /etc/apt/keyrings/docker.asc # Add the repository to Apt sources: echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ sudo tee /etc/apt/sources.list.d/docker.list > /dev/null sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
SELECT stuff, count(*) OVER() AS total_count FROM table WHERE .... ORDER BY ... OFFSET 0 LIMIT 10
docker compose up -d
import Knex from "knex"; const knex = Knex({ client: 'pg', connection: process.env.DATABASE_URL, }); const records = [ { id: 2, login: "admin" }, ]; async function upsert() { const result = await knex.raw( `? ON CONFLICT (id) DO UPDATE SET login = EXCLUDED.login, updated_at = CURRENT_TIMESTAMP RETURNING *;`, [knex("users").insert(records)], ); }
pkill -9 -f pattern
???
SELECT 'SELECT SETVAL(' || quote_literal(quote_ident(sequence_namespace.nspname) || '.' || quote_ident(class_sequence.relname)) || ', COALESCE(MAX(' ||quote_ident(pg_attribute.attname)|| '), 1) ) FROM ' || quote_ident(table_namespace.nspname)|| '.'||quote_ident(class_table.relname)|| ';' FROM pg_depend INNER JOIN pg_class AS class_sequence ON class_sequence.oid = pg_depend.objid AND class_sequence.relkind = 'S' INNER JOIN pg_class AS class_table ON class_table.oid = pg_depend.refobjid INNER JOIN pg_attribute ON pg_attribute.attrelid = class_table.oid AND pg_depend.refobjsubid = pg_attribute.attnum INNER JOIN pg_namespace as table_namespace ON table_namespace.oid = class_table.relnamespace INNER JOIN pg_namespace AS sequence_namespace ON sequence_namespace.oid = class_sequence.relnamespace ORDER BY sequence_namespace.nspname, class_sequence.relname;Alternatives List of all sequence
SELECT c.relname FROM pg_class c WHERE c.relkind = 'S' order BY c.relname;Fix sequence (if it's named id)
SELECT concat('SELECT SETVAL(''public.', c.relname,''', COALESCE(MAX(id), 1) ) FROM public.', replace(c.relname, '_id_seq', ''), ';') FROM pg_class c WHERE c.relkind = 'S' order BY c.relname;
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - sudo apt-get install -y nodejs
docker cp <source_path> <container_id>:<destination_path> docker cp <container_id>:<source_path> <destination_path>
openssl rand -base64 32
proxy_cache_path /home/nginx levels=1:2 keys_zone=CACHE:50m max_size=12G inactive=30d; server { server_name example.com; location / { proxy_cache_key "$uri"; proxy_pass https://$path$is_args$args; resolver 8.8.8.8; proxy_cache CACHE; access_log off; expires max; add_header X-Proxy-Cache $upstream_cache_status; proxy_set_header Referer ""; proxy_cache_valid 200 30d; proxy_cache_valid 403 10m; proxy_cache_valid 404 10m; proxy_ssl_server_name on; proxy_ssl_name $proxy_host; } listen 443 ssl; # managed by Certbot ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot }
sudo sh -c "echo -n 'sammy:' >> /etc/nginx/.htpasswd" sudo sh -c "openssl passwd -apr1 >> /etc/nginx/.htpasswd"
systemctl list-units --type service