Categories
Linux Raspberry PI

Linux miscellaneous

Pertains mostly to Ubuntu 18.04.4 and Apache 2.4.29

Get Ubuntu version

lsb_release -a

Get Apache version

apache2 -v

Get MySql version

mysql --version

Find Files and hide all permission denied messages

find /start_directory -name filename 2>/dev/null

Copy file with ssh from server to localhost

scp user@server:/directory_from/filename.txt /local_directory/

Copy file from localhost to server with ssh

scp file_to_copy.txt user@servername:/directory_to_copy_to/

Copy directory from server recursively with ssh

scp -r user@server:/directory_from /local_directory/

Copy directory to server from localhost recursively with ssh

$ scp -r /local_directory/ user@server:/server_directory/

Copy directory with ftp recursively into current directory

sudo wget -r ftp://user:password@server/folder1/folder2/filename

To use ftp to put files onto a server recursively

ncftpput -R -v -u user -p password -P 21 ftp.server.com /directory_to_copy_to /directory_to_copy_from

Import .sql into MySql

mysql -uUser -pPassword Database < sql_file.sql

To export MySql table to .sql file

sudo mysqldump database table -uUsername -pPassword > sql_file.sql
Categories
MySql php wordpress

Exporting/Importing Woocommerce Orders with SQL 2020

Covers WordPress version 5.3.2

No matter how you use the SQL, be it on the command line, PhpMyAdmin or PHP, These are just the SQL commands needed.

There are 4 tables invlovled not counting the variable product data. I’ll be adding that as soon as a get a free moment.

  • wp_posts
  • wp_postmeta
  • wp_woocommerce_order_items
  • wp_woocommerce_order_itemmeta

wp_posts are where the main orders are kepts, with the post_id being the actual order ID. The other 3 tables use this id to attach items, customer details, etc to the order.

wp_postmeta contains the customer data.

wp_woocommerce_order_items contains the items that are ordered.

wp_woocommerce_order_itemmeta contains the price, etc of the items ordered.

So, on to the SQL by example

SELECT * FROM wp_posts WHERE post_type="shop_order"  and date(post_date)=date("2020-02-25")

The main thing is the “shop_order” post type. If you leve out the date part of the SQL then obviously you will get all orders in the database. If using PhpMyAdmin you can then simply export the results, os CLI pipe to a file, whatever, saving the data into something like wp_posts.sql

Now assuming a list of orders with post_id’s of 11538, 11541,11542, 11543, 11533, 11534, 11535, 11536, 11537, 11539, 11540 was resturned. We need to get all the info for those numbers starting with wp_postmeta.

SELECT * FROM wp_posts WHERE post_type="shop_order"  and date(post_date)=date("2020-02-25")

Save the results to wp_postmeta.sql.

SELECT * FROM wp_woocommerce_order_items WHERE order_id in (11538,11541,11542,11543,11533,11534,11535,11536,11537,11539,11540)

This will give us the items ordered, so save teh results to wp_woocommerce_order_items.sql.

SELECT * FROM wp_woocommerce_order_itemmeta WHERE order_item_id in (11538,11541,11542,11543,11533,11534,11535,11536,11537,11539,11540)

And save these results to wp_woocommerce_order_itemmeta.sql.

So now we have 4 sql files containing the orders and order data that we want to import, possibly on another server. The assumption at this point is the users exist already, otherwise you will have to export the users as well which is beyond the scope of this blog.

If would/could be a very, very bad idea so simply import as it, as chances are the key values are already in use.

The plan therefore is simple, edit the .sql files and change them to a number higher that what exists in the database you are importing to.

So you would change the post_id in the first file, then edit the second file to point to the new numbers you created, as well as create new meta_id values, and so forth. All the id numbers in the 4 files must match up.

Then you can simply import the 4 files into the new database, and there you go, your orders have been imported.

Summary

SELECT * FROM wp_posts WHERE post_type="shop_order"  and date(post_date)=date("2020-02-25")

SELECT * FROM wp_postmeta WHERE post_id in (11538,11541,11542,11543,11533,11534,11535,11536,11537,11539,11540)

SELECT * FROM wp_woocommerce_order_items WHERE order_id in (11538,11541,11542,11543,11533,11534,11535,11536,11537,11539,11540,11545)

SELECT * FROM wp_woocommerce_order_itemmeta WHERE order_item_id in (11538,11541,11542,11543,11533,11534,11535,11536,11537,11539,11540,11545)

Thank you for your time, I hope this helps.

Categories
Linux Viynl Cutter

Sharing a Viynl Cutter over the Network in Linux

This setup works for a cheap Chinese no name brand Cutting Plotter I use.

On the host PC add a new printer and set the printer model to “Raw Queue

Set the device URI to, for example, serial:/dev/ttyUSB0?baud=9600. This assumes the servial device is attached to USB port 0.

Make sure it is shared.

On the slave PC simply add the network printer

Enjoy. 

Categories
Inkscape Linux Viynl Cutter

Setting up Inkscape for use with a Vinyl Cutter using Inkcut

Step 1

Download and install the InkCut Extension from the InkCut sourceforge page.

Step 2

Install the following linux libraries :


		sudo apt-get install python-gtk2-dev
		sudo apt-get install python-cups
		sudo apt-get install python-serial
		

Using InkCut to perform the cut

Step 1

Select the objects you wish to cut

Step 2

Ungroup the selected objects

Step 3

Go “Path->Object to Path”

Step 4

Go “Path->Union”

Step 5

Extensions->Cutter/Plotter->Inkcut v1.0

Categories
Linux Raspberry PI

Raspberry PI Setup

  • use GParted to format SD to win32.
  • sudo dd bs=4M status=progress if=~/Downloads/2018-06-27-raspbian-stretch.img of=/dev/sdc; sync
    NB note /dev/sdc, not /dev/sdb1. i.e. Must point to physical device, not partition.
  • Edit config.txt on the SD to set hdmi hot plug support.
  • put sd in the pi, plug in kb and monitor and boot.
  • after install and upgrade process (including setting new password), go to pi configuration and enable ssh and vnc (and camera if attached)
  • reboot pi for changes to take effect.
  • install vnc viewer on pc, and log into the pi.
  • tada, you are up and running on the pi.